← 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?
- A.Creates a Student with name null
- B.Compile error: no no-argument constructor exists
- C.Creates a Student with name ""
- 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 →