📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    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 Correct Answer Incorrect Answer
    B Drawing a generic shape Drawing a generic shape Drawing a generic shape Correct Answer Incorrect Answer
    C Drawing a circle Drawing a circle Drawing a circle Correct Answer Incorrect Answer
    D Drawing a rectangle Drawing a rectangle Drawing a rectangle Correct Answer Incorrect Answer
    E A compile-time error. Correct Answer Incorrect Answer

    Solution

    The correct answer is A

    Practice Next
    More IT Operating System Questions
    ask-question