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.
The protection of constitutional safeguards for civil servants is guaranteed by which Article?
Who launched the 'Bharat 6G Alliance' in New Delhi?
Which districts of Uttarakhand has been selected as the aspirational district under Swajal 2.0?
Mytella strigata, recently seen in the news, is a:
With reference to the Exclusive Economic Zone (EEZ), consider the following statements:
1.Each coastal State may claim an EEZ beyond and adjacent...
In which city the e-waste eco-park was announced on the 12th June 2025?
Which private bank raised ₹3,925 crore through infrastructure bonds in FY25?
Which of the following is an example of system software?
Which country is collaborating with India to build the 'Yug Yugin Bharat Sangrahalaya', a proposed cultural and historical museum?
Recently seems in the news, Vaigai Dam is located in which one of the following States?