Example 1: Java Inheritance eat(); Here, labrador is an object of Dog . However, name and eat() are the members of the Animal class. Since Dog inherits the field and method from Animal , we are able to access the field and method using the object of the Dog .
What is the example of inheritance in Java?
Example 1: Java Inheritance eat(); Here, labrador is an object of Dog . However, name and eat() are the members of the Animal class. Since Dog inherits the field and method from Animal , we are able to access the field and method using the object of the Dog .