Question
Which of the following scenarios illustrates runtime
polymorphism?Solution
Runtime polymorphism (or dynamic method dispatch) occurs when a method's implementation is determined at runtime. This is achieved using method overriding in OOP. A derived class overrides a method of the base class, and the method to execute is determined by the type of the object being referenced at runtime. Example: class Animal {   void sound() {     System.out.println("Animal makes a sound");   }} class Dog extends Animal {   void sound() {     System.out.println("Dog barks");   }} public class Main {   public static void main(String[] args) {     Animal animal = new Dog(); // Base class reference pointing to a derived class object     animal.sound();      // Outputs: Dog barks   }} Why Other Options Are Incorrect: 1. Method with the same name but different parameters within the same class: This is compile-time polymorphism (method overloading), not runtime polymorphism. 2. Default arguments in methods: Default arguments provide flexibility but are unrelated to polymorphism. They simplify method calls without changing the behavior based on the object’s runtime type. 3. Static methods for shared functionality: Static methods are class-level and cannot participate in runtime polymorphism, as they are resolved at compile time. 4. Constructor with a parameter list in the derived class: Constructors are not polymorphic as they do not inherit or override behavior in OOP.
What is the total operational testing time planned for the DRDO desalination membrane?
What is the total area covered by Pobitora Wildlife Sanctuary in Assam?
Which country commissioned its first submarine base at Pekua in Cox’s Bazar?Â
Which of the following regulatory body issues fresh guidelines Demat Debit and Pledge Instruction to curb misuse of clients’ Power of Attorney?
How many ASEAN countries are currently part of the association as of the Cruise Dialogue event?
How many award categories were presented during the National Highways Excellence Awards 2023?
Which country topped the global list of Best Cuisines, 2022 in the Taste Atlas report?
What amount is the cash prize associated with the Khel Ratna Award?
Which indigenously developed explosive was successfully tested by the Indian Navy, marking a significant achievement in India's defense self-reliance?
- Which renowned Odissi dancer, credited with introducing Sanchari Bhava, Mudra Viniyoga, and Rasa Theory into Odissi, passed away at the age of 92 in 2025?