Ask Question
27 December, 00:16

What is a Java constructor?

+4
Answers (2)
  1. 27 December, 01:32
    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. 27 December, 02:00
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers