Start learning 50% faster. Sign in now
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.
Two trains ‘A’ and ‘B’ started from station ‘P’ and ‘Q’ towards station ‘Q’ and ‘P’ respectively at the same time. When they met...
A goods train leaves a station at a certain time and at a fixed speed. After 12 hours, an express train leaves the same station and moves in the same di...
A train traveling at 43.2 km/h takes 'm' seconds to pass a pole. What is the length of the train in meters?
Train A running at speed of 99 km/hr crosses a platform having twice the length of train in 18 sec. Train B whose length is 390m crosses same platform i...
A train passes an electrical pole in 15 seconds and passes a platform 420 m long in 60 seconds. Find the length of the train.
Without stopping the speed of the train is 130 kmph, with stopping the speed of the train is 65 kmph.Find the stop time of the train?
A train 600 metres long is running at a speed of 54 km/hr. If it crosses a tunnel in 1 minute, then the length of the tunnel (in meters) is:
Train ‘A’ running with a speed of 19.8 km/hr can cross a standing goods train of 4 times its length in 40 seconds. Find the time taken by 250 metres...
Two trains are running on parallel lines in the same direction at the speed of 76 km/h and 40 km/h respectively. The faster train crosses a man in the s...
Two trains, whose respective lengths are 120 metres and 180 metres, cross each other in 15 seconds when they are moving in opposite directions and in 5...