Java OCA OCP Practice Question 300

Question

Which is a valid constructor for this class?

public class MyClass { 
} 
  • A. public MyClass static create() { return new MyClass(); }
  • B. public MyClass static newInstance() { return new MyClass():}
  • C. public MyClass() {}
  • D. public void MyClass() {}


C.

Note

Options A and B are static methods rather than constructors.

Option D is a method that happens to have the same name as the class.

It is not a constructor because constructors don't have return types.




PreviousNext

Related