Question

In Object-Oriented Programming, which of the following Java code snippets correctly demonstrates inheritance ? class Animal {                                            void sound () {         System.out.println( "Animal makes a sound" );     }} class Dog extends Animal {     void sound () {         System.out.println( "Dog barks" );     }}

A The Dog class correctly overrides the sound() method from the Animal class.
B The Dog class cannot override the sound() method from the Animal class.
C The Dog class is inheriting the sound() method from the Animal class but not overriding it.
D The Animal class should be an abstract class to allow method overriding
E The Dog class should not inherit from Animal.
Practice Next

Hey! Ask a query