155k views
3 votes
What happens when a returntype, even void, is specified as a constructor in Java?

1 Answer

3 votes

Answer:

If a returntype is added to a constructor method in Java, it ceases to be a constructor and behaves like an ordinary class method with the same name as class name.

Step-by-step explanation:

If a returntype is added to a constructor method in Java, it ceases to be a constructor and behaves like an ordinary class method with the same name as class name.

Constructors are special methods which are used for initializing the object. Constructors do not have a return type. If we add a return type to the constructor method , it does not play any role during object initialization and can be involved like any other object method.

User Bilal Usean
by
6.4k points