Computer Science, asked by Anonymous, 1 year ago

icse java--

advantage of constructor

Answers

Answered by Anonymous
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 Millii
1

A constructor is a block code that initializes the newly created object.

Advantages of Constructor

  1. You can give a factory method a more descriptive name (whereas of course a standard constructor has to be named after the containing class).
  2. They don't have to return an object, giving more flexibility.
  3. They can return a sub-types of the class.

Similar questions