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 was India's external debt at end March 2024?
What is the maximum loan amount under the third tranche of the PM SVANidhi Scheme?
Risks that could arise due to legal actions or uncertainty of interpretations of contracts & agreements is called
What are the instruments which are offered to finance short term debt obligations of government of India?
Which of the following is not a step in the Risk Management Process?
Which of the following is correct regarding Reinvestment Risk?
i. When I...
The Asset Liability Management (ALM) Statement is to be prepared by every bank and is a regulatory requirement. It shows the maturity time-wise break-up...
Persons other than individuals can remit funds overseas, towards donations for certain specified purposes, up-to ____
Which of the following statement is true?
A beneficiary of Stand Up India Scheme will be able to avail the services through which of the following ways?
I- Directly at the branch
I...