Explain inheritance with Examples.

Consider the example class Actor below:
public class Actor {
public void act(){

We can extend this class by using the keyword extends. Hero class extends Actor.
//IS-A relationship. Hero is-a Actor

public class Hero extends Actor {
public void fight(){

We can now create an instance of Hero class. Since Hero extends Animal, the methods defined in Animal are also available through an instance of Hero class. In the example below, we invoke the act method on hero object.

Hero hero = new Hero();
//act method inherited from Actor