Question: Q 1 . What is printed by the following code? Consider the polymorphic invocation. Verify your answer by writing the code in your IDE (

Q1. What is printed by the following code? Consider the polymorphic invocation. Verify your answer by writing
the code in your IDE (e.g. Eclipse) and observing the output.
public class Practice1{
Practice1(){
Figure f= new Figure(() ;
Rectangle r= new Rectangle();
Box b= new Box();
f.display();
f=r;
f.display();
f=b;
}
f.display();
public static void main(String[] args){
new Practice1();
}
class Figure {
}
void display(){System.out.println("Figure"); }
class Rectangle extends Figure {
void display(){System.out.println("Rectangle"); }
}
class Box {
void display(){System.out.println("Box"); }
}
}
Q 1 . What is printed by the following code?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!