icse java--
advantage of constructor
Answers
Answered by
1
Hey mate!!!
Constructors have the same name as that of the class they belong to. Constructors are executed when an object is declared. The main function of constructor is to initialize objects and allocate appropriate memory to objects. Though constructors are executed implicitly, they can be invoked explicitly.
Hope this helps you.
Mark as brainliest.
Answered by
1
A constructor is a block code that initializes the newly created object.
Advantages of Constructor
- You can give a factory method a more descriptive name (whereas of course a standard constructor has to be named after the containing class).
- They don't have to return an object, giving more flexibility.
- They can return a sub-types of the class.
Similar questions