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.
In which part of India is Dandakaranaya situated?
In which atmospheric layer is there no decrease in temperature with an increase in altitude?
Which countries does the Somali Current flow past in the Western Indian Ocean?
What is the characteristic feature of Narmada Valley?
Consider the following statements:
1. The La Nina is the “cool phase” of El Nino-Southern Oscillation (ENSO).
2. The La Nina event hap...
The largest coral reef in the world is found off the coast of which country.
An exoplanet is defined as:
What percent of the earth’s surface is covered by the Atlantic Ocean?
Which of the following is a part of the Eastern coast?
Which one of the following longitudes determines the Indian standard time?