🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Object Initialization Order: all 10 questions

Quiz: Object Initialization Order · Question 5 of 10

Parent Person has only the constructor Person(String name). What happens with class Student extends Person { Student()…

Parent Person has only the constructor Person(String name). What happens with class Student extends Person { Student() { } }?

  1. A.Compile error, because the hidden super() has no matching constructor
  2. B.It compiles and name is null
  3. C.Runtime NullPointerException
  4. D.Java creates a no-argument constructor in Person automatically
Answer & explanation

Correct answer: Compile error, because the hidden super() has no matching constructor

Java adds a default constructor only to a class with no constructors at all.

Can you get the rest right without peeking?

Take the timed Quiz: Object Initialization Order quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →