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


    Question

    Consider a Shape class with a method draw(), and Circle

    and Rectangle classes that inherit from Shape and override draw(). If you have a List containing Circle and Rectangle objects, calling draw() on each element demonstrates:
    A Encapsulation Correct Answer Incorrect Answer
    B Abstraction Correct Answer Incorrect Answer
    C Inheritance Correct Answer Incorrect Answer
    D Polymorphism Correct Answer Incorrect Answer
    E Composition Correct Answer Incorrect Answer

    Solution

    This is a classic example of runtime polymorphism. Even though the list holds references of type Shape, when draw() is called, the specific draw() method of the actual object (either Circle or Rectangle) is executed. The same method call (draw()) behaves differently based on the object's type.

    Practice Next
    ask-question