Question
Consider the following code snippet (Java-like):
  class Animal {     public void makeSound() {       System.out.println("Animal makes a sound");     }   }   class Dog extends Animal {     @Override     public void makeSound() {       System.out.println("Dog barks");     }   }   public class Test {     public static void main(String[] args) {       Animal myAnimal = new Dog();       myAnimal.makeSound();     }   }   What will be the output of this code?Solution
This demonstrates runtime polymorphism (method overriding). Even though myAnimal is declared as type Animal, it actually refers to a Dog object. When makeSound() is called, the JVM (Java Virtual Machine) determines the actual type of the object at runtime and invokes the makeSound() method defined in the Dog class.
What is the key objective of the Indian government's scheme to boost pulses output?
Which of the following countries does Punjab National Bank (PNB) currently not have a presence in?
What is the target number of women entrepreneurs under the Lakhpati Didi mission supported by MoRD and MSDE?
Who becomes the first woman to achieve a $100 billion fortune, and what is the primary reason for this milestone?
What is the budgetary outlay for Ken Betwa river linking project?
Which of the following statements is true regarding the MEDITECH STACKATHON 2024 launched in New Delhi?
The Saubhagya Scheme aims to achieve which of the following?
Which rivers are included in the ‘Jalvahak’ scheme to promote cargo movement on National Waterways?
Which of the following statements is/are not true regarding the proposed changes/changes being done by the Monetary Policy Committee?
I.The Reser...
According to a report by CBRE, what is the projected number of new senior living facilities in India in the next 10 years? Â