1.

Define What Is Constructor ?

Answer»

A constructor is a method that is called when a NEW instance of an object of a class is created. It INITIALIZES all class members whenever you create an object of the class. It is a member function with the same name as its class. It may or may not take any parameters. It does not have any return type. For example, the compiler embeds a call to the constructor for each object when it is created. SUPPOSE a class Z has been declared as FOLLOWS:


We cannot DECLARE a constructor as virtual or static, nor we can declare a constructor as const, volatile, or const volatile. The short form of constructor is ctor.

A constructor is a method that is called when a new instance of an object of a class is created. It initializes all class members whenever you create an object of the class. It is a member function with the same name as its class. It may or may not take any parameters. It does not have any return type. For example, the compiler embeds a call to the constructor for each object when it is created. Suppose a class Z has been declared as follows:


We cannot declare a constructor as virtual or static, nor we can declare a constructor as const, volatile, or const volatile. The short form of constructor is ctor.



Discussion

No Comment Found