Multiple choice

What happens in the heap memory when a subclass object is created?

  1. Only for the subclass object, memory will be created.

  2. Only for the superclass object, memory will be created.

  3. Memory for both superclass and subclass will be created and also that memory is referenced by super class reference variable.

  4. Memory for both superclass and subclass will be created and also that memory is referenced by subclass reference variable.

  5. None of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

When subclass object is created memory allocated for superclass object in association with subclass object. So with the subclass reference variable it is possible to access that memory.