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

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

Want to excel in Java? Test your knowledge with our ultimate quiz based on 'Thinking in Java'. Engage with multiple-choice questions and in-depth explanations. Boost your understanding and prepare for your exam with confidence.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

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.