Which of the following is a valid constructor declaration in Java?

  • MyConstructor() {}
  • public MyConstructor() {}
  • public int MyConstructor() {}
  • void MyConstructor() {}
In Java, a valid constructor declaration doesn't specify a return type, and its name should match the class name. So, MyConstructor() {} is a valid constructor declaration. The other options are invalid because they specify a return type or access modifier.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *