Q. When is a constructor called?
A. A constructors is called during object creation.
Q. What are the characteristics of a constructor?
Ans. 1. A constructor has the same name as that of the class.
2. A constructor has no return type, not even void.
3. A constructor is automatically called on object creation.
4. If no constructor is defined, then the compiler provides a default constructor.
5. A constructor can accept parameters. Such a constructor is known as a parameterised constructor.
Q. What is the difference between a default constructor and a parameterised constructor?
A. A default constructor doesn’t accept any parameters. A parameterised constructor accepts parameters.
Q. What does the default constructor provided by the compiler do?
A. The default constructor provided by the compiler initializes all instances variables to their default values. It initialises integers to 0, floating point numbers to 0.0, boolean values to false and objects to null.
Q. What is a destructor
A. A destructor is a method which is executed when the object is removed from computer’s memory.