Ask Question

What is a Java constructor?

+5
Answers (2)
  1. 23 June, 05:27
    0
    Java constructor is a special method defined in a class whose name s the same as the class name

    Explanation:

    Java constructor is a special method defined in a class whose name is the same as the class name.

    The constructor is called when the object is instantiated to initialize the fields in the object. Constructor can have no arguments or it can carry one or more arguments as per the class design. A default no argument constructor is made available for a class automatically even if one is not explicitly defined.

    For example: MyClass c = new MyClass ();

    This will call the zero argument constructor of MyClass if it is defined or otherwise the default constructor for MyClass.
  2. 23 June, 05:33
    0
    A Java constructor is special method that is called when an object is instantiated. In other words, when you use the new keyword. The constructor initializes the newly created object.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is a Java constructor? ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers