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.
Ratna variety of Mango isa cross of ?
Live microbial supplements that benefited human health by the microbial balance in the intestine called
Which ministry is responsible for implementing the Agricultural Export Policy in India?
Calculate the seed rate (kg/ha) of wheat, if crop is sown at spacing of 18 cm×3 cm and rest weight of seed is 44 gram
What is the primary symptom of myxomatosis in rabbits?
Among the given crops, which crop has the highest percentage of irrigated area?
The element found on the surface of the moon is:
The hydraulic brakes used in automobiles is a direct application of :
Which layer of the atmosphere is responsible for most of the Earth's weather patterns?
Rapid fall in the activity of metabolic processes especially respiration in crop plants due to decrease in temperature up to 0 to 10oC and m...