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.
If a wheel covers a distance of 660 m in 30 rotations, then the diameter of the wheel is?
Find the area of largest square that can be inscribed in a circle of radius ‘r’.
In a circle, two chords AB & CD are produced at P which is outside the circle . If PA= 18 cm, AB= 12 cm , PC = 6 cm then find CD.
In the given figure, ABC and MNC are two secants of a circle which intersect each other at C outside the circle. AN is the diameter of the Circle. If an...
In a circle, two chords AB & CD are produced at P which is outside the circle . If PA= 12 cm, AB= 10 cm , PC = 2 cm then find CD.
Sum of diameter and circumference of a circle is 232 cm, the find area of circle.
The wheel of a car made 300 rotations. How much distance did the car travel if the diameter of the wheel is 28 inches? (1 inch = 2.54cm)
One chord of a circle is given as 18.5 cm. Then the radius (r) of the circle must be:
A sector of a circle has a central angle of 90°. If the radius of the circle is 10 cm, what is the area of the sector?
In a circle of radius 13 cm, a chord is 5 cm from the center. Find chord length.