Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


How can one constructor call another constructor in the same class?

  1. Using super()

  2. Using this()

  3. Using init()

  4. Directly calling the constructor by name

The correct answer is: Using this()

One constructor can call another constructor in the same class by using the keyword "this" followed by parenthesis and any necessary arguments. This is known as constructor chaining and allows the code to be more organized and easier to maintain. In contrast, super() is used to call a constructor from a superclass, init() is not a valid keyword for calling constructors, and directly calling the constructor by name is not a recommended practice and can lead to code duplication and confusion.