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

Quiz: Java Classes and Objects · Question 7 of 10

A class has only the constructor Student(String name). What does new Student() do?

A class has only the constructor Student(String name). What does new Student() do?

  1. A.Creates a Student with name null
  2. B.Compile error: no no-argument constructor exists
  3. C.Creates a Student with name ""
  4. D.Throws an exception at run time
Answer & explanation

Correct answer: Compile error: no no-argument constructor exists

Java adds a default constructor only when the class declares none. Once you write one, you must also write Student() if you need it.

Can you get the rest right without peeking?

Take the timed Quiz: Java Classes and Objects quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →