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 is the address of an object printed using the 'this' keyword inside its toString() method?

  1. Directly using this.toString()

  2. Using super.toString()

  3. By converting 'this' to a string

  4. By utilizing System.out.toString(this)

The correct answer is: Using super.toString()

B is the correct answer because using the 'super' keyword allows us to access the toString() method of the parent class, which outputs the object's address. Additionally, options A and C are incorrect because they do not utilize the 'super' keyword. Option D is incorrect because System.out.toString() is not a valid method and cannot be used with the 'this' keyword.