Question

.Consider the following Java code: class Shape {     void draw() {         System.out.println("Drawing a generic shape");     } } class Circle extends Shape {     @Override     void draw() {         System.out.println("Drawing a circle");     } } class Rectangle extends Shape {     @Override     void draw() {         System.out.println("Drawing a rectangle");     } } public class TestPolymorphism {     public static void main(String[] args) {         Shape s1 = new Circle();         Shape s2 = new Rectangle();         Shape s3 = new Shape();         s1.draw();         s2.draw();         s3.draw();     } } What will be the output of this code?

A Drawing a circle Drawing a rectangle Drawing a generic shape
B Drawing a generic shape Drawing a generic shape Drawing a generic shape
C Drawing a circle Drawing a circle Drawing a circle
D Drawing a rectangle Drawing a rectangle Drawing a rectangle
E A compile-time error.
Practice Next

Hey! Ask a query