OCA Java SE 8 Method - OCA Mock Question Method 15








Question

Which of these classes compile and use a default constructor? (Choose all that apply)

  1. public class Student { }
  2. public class Student { public student() {} }
  3. public class Student { public student(String n) {} }
  4. public class Student { public Student() {} }
  5. public class Student { Student(String n) {} }
  6. public class Student { private Student(int i) {} }
  7. public class Student { void Student() { }




Answer



A, G.

Note

A does not define a constructor and a default constructor is provided.

B and C don't compile because the constructor name must match the classname.

E, and F all compile. Since a constructor is coded, a default constructor isn't supplied.

G defines a method, but not a constructor.