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.


Is it possible to upcast from a derived class to a base class in Java?

  1. Casting a base class reference to a derived class

  2. Casting a derived class reference to a base class

  3. Forcing garbage collection of a derived class object

  4. Creating an abstract method in the derived class

The correct answer is: Casting a base class reference to a derived class

Upcasting in Java refers to the act of casting a reference of a base class to a reference of a derived class. This allows for the use of methods and variables that are specific to the derived class. Option B is incorrect because it refers to downcasting instead, which is the opposite of upcasting. Option C is incorrect because garbage collection is not related to upcasting. Option D is incorrect because creating an abstract method is not specific to upcasting.