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.
Statements:
Only a few Lotions is Bands.
Only a few Lipsticks is Lotions.
No Lipsticks is Cream.
Conclusions:
I. Ever...
Select the option that is related to the first number in the same way as the third number is related to the fourth number.
729: ? :: 432: 408
Who lives on 4TH floor?
Statements:
No kite is a thread.
A few threads are needles.
Only needles are sticks.
Conclusions:
I. A few threads may be sticks.
II. No kite is a needle.
Select the option that is related to the third word in the same way as the second word is related to the first word.
Clay: Pottery :: Wheat : ?
If Pi is the brother of Qi, Bi is the brother of Qi and Pi is the brother of Ei, then which of the following statements is definitely true?
If all the vowels in the word ‘USEFUL’ are changed to the next letter in the English alphabetical order and all the consonants remain the same then ...
If F = 6 and TRIAL = 60, then OBVIOUS =
Pointing to the photograph of a boy, Lakshmi said, “He is my father’s sister’s husband’s daughter’s brother.” How is that boy in photograph ...
How many pairs of letters are there in the word ‘CONSUMPTION’, which has as many letters between them (Only forward) in the word as in the English a...