How are the object properties of a class initialized?

Updated on technology 2024-08-05
6 answers
  1. Anonymous users2024-02-15

    To instance an object in a class, you can't.

    1)private company com=new company();

    2)private company com;

    com = new company();

  2. Anonymous users2024-02-14

    inti=0;

    classemployee

    public:

    employee(){

    In this case, the array is initialized.

    For example: for(i=0; i<15;i++)name[i]='x';

    employee(char*,char*,char*,char*);

    voidchange

    name();

    voiddiapiay();

    employee(){

    private:

    charname[15],address[50],city[15],youbian[10];

    This is the class you define, you can initialize your array in the constructor, and when you instantiate a class object, the constructor will be automatically called...

  3. Anonymous users2024-02-13

    Static first, then members, then constructs.

  4. Anonymous users2024-02-12

    If you don't need it, it won't be loaded into memory at all, and it's impossible to initialize!

    I can't think of any language that was initialized in the compiler...

  5. Anonymous users2024-02-11

    Hello, initialization allows a class to have its own property values as soon as it spawns an object.

    Such as creating a person initializing his name, age, etc.

    As soon as the person is created, the object has property values such as name, age, etc.

    Of course, you can also call the method to initialize when needed.

  6. Anonymous users2024-02-10

    1) Initialization of the lease key for non-static objects.

    When you create an object, all data members of the class in which the object is located are initialized first.

    Basic type: int, initialized to 0.

    If objects: These objects are initialized sequentially.

    After all classes have been initialized, the constructor of the class is called to create the object.

    The purpose of the constructor is initialization.

    2) Initialization of static objects.

    The static variables of the main class in the program are initialized before the main method is executed.

    Not only is it the first time you create an object, all the static variables in the class are initialized, and the first time you access a class (note this time.

    No such object is created), the detrimental static variables are also initialized in the order in which they appear in the class.

Related questions
19 answers2024-08-05

In fact, when calling the member function of the class, the value of this will be passed into the first parameter by default, which is mainly used to access the member variables of the class. >>>More

10 answers2024-08-05

No, it's like a 3-year-old can write, but another 3-year-old can't. But if you teach him, he will. The two distinctions are like white and green generals. >>>More

5 answers2024-08-05

Objects and classes, for example, are not difficult to understand. >>>More

6 answers2024-08-05

I don't know if you know anything about memory allocation. >>>More

4 answers2024-08-05

A class is the definition of an object, and an object is an instance of a class.