Question
What does the following Java code snippet
demonstrate? class Animal { Â Â void sound() { System.out.println("Some sound"); } } class Dog extends Animal { Â Â void sound() { System.out.println("Bark"); } }Solution
Method overriding occurs when a subclass (Dog) provides a specific implementation of a method already defined in its superclass (Animal) with the same name, return type, and parameters. The JVM decides at runtime which version to call based on the actual object type. Tthis is runtime polymorphism. Method overloading (compile-time polymorphism) uses the same method name with different parameters within the same class.
Cinnabar is an ore of which metal?
Which gas is the chief component of Bio-gas?
Which of the following is used in alcoholic drinks?
Whose experiments supports Abiotic synthesis?
Which of the following pollutants is the major contributor to photochemical smog?
Which of the following fatty acids does NOT form soap?
Which of the following is the richest source of phosphorus?
"Schist" is the example of which type of rock?
Which element is known as the 'King of Chemicals.
_____________ has the maximum attraction force between the molecules.