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.
(a) It was amazing to see ,how Alisha could _________ her composure.
(b) It will cost a hefty amount to __________ as good an employee as him.
Onion prices in India have been _______ yet again and citizen across the country are having to significantly stretch their financial budget to make do w...
Choose the correct answer to fill the given blank
The cat _____ on the windowsill for hours.
They sat by the river bank with their legs ______ in the water.
Choose the correct answer to fill the given blank
The company's profits _____ last year.
_____ the new government may formulate some policies within the 12-18 month horizon of this outlook, it will take _____ to see an impact on the real...
Select the most Appropriate option to fill in blank
Health should be our first priority and should neeever be -------------
Fill in the blanks with appropriate words/phrases from the options.
According to the ED, a _____________ portion of over ₹800 crore taken in ...
Any further delay in helping the sector to get back on track would cause __________ damage, since the threat of the sector being taken over by bus-aggre...
In each of the following sentences there is one blank space. Find out which word can be filled up in the blanks in sentence in the same sequence to mak...