Final answer:
The output printed would be Rectangle and Rectangle as explained in the detailed answer.
The correct answer is: b) Rectangle Figure.
Step-by-step explanation:
The code given creates a class hierarchy with an abstract class called Figure, an abstract class called Rectangle that extends Figure, and a class called Box that extends Rectangle. Within the Inherit class, an instance of Box is created and assigned to a reference variable of type Figure.
When the display() method is called on this instance, the output would be Rectangle. Then, the reference variable f is casted to type Rectangle and assigned to r. When the display() method is called on r, the output would still be Rectangle as r still refers to the same instance of Box created earlier.
The code defines an abstract class Figure with a non-abstract method display() that prints "Figure". Rectangle is an abstract subclass of Figure, and Box is a concrete subclass of Rectangle with an overridden display() method that prints "Rectangle".
When an instance of Box is created, it is upcast to Figure type and the display() method is invoked, then Box is cast to Rectangle, and its display() method is invoked again.
Due to polymorphism, in both cases, the overridden display() method in the Box class will be called. Therefore, the output of the program is: Rectangle