Computer Science, asked by shashwatprathmesh0, 4 months ago

In the source file,a constructor looks like a _____ in which method has the same name as the class but has no_____​

Answers

Answered by neetutiwari2222
0

Answer:

A constructor resembles an instance method, but it differs from a method in that it has no explicit return type, it is not implicitly inherited and it usually has different rules for scope modifiers. Constructors often have the same name as the declaring class. They have the task of initializing the object's data members and of establishing the invariant of the class, failing if the invariant is invalid. A properly written constructor leaves the resulting object in a valid state. Immutable objects must be initialized in a constructor.

Most languages allow overloading the constructor in that there can be more than one constructor for a class, with differing parameters. Some languages take consideration of some special types of constructors. Constructors, which concretely use a single class to create objects and return a new instance of the class, are abstracted by factories, which also create objects but can do so in various ways, using multiple classes or different allocation schemes such as an object pool.

Answered by milindupadhyay9
0

Answer:

In the source file,a constructor looks like a engineer in which the method has the same name as the class but has no position.

Similar questions