KnowledgeBoat Logo

Computer Applications

Why is an object not passed to a constructor by value? Explain.

Java Constructors

51 Likes

Answer

Constructors are special member methods of the class. Objects are non-primitive data types so they are passed by reference and not by value to constructors. If objects were passed by value to a constructor then to copy the objects from actual arguments to formal arguments, Java would again invoke the constructor. This would lead to an endless circular loop of constructor calls.

Answered By

27 Likes


Related Questions