How to Use Inheritance (extends) in Java


In this example we will show how to use inheritance (extends) in Java.

Source Code

package com.beginner.examples;

class Animal {
  public void yell() {
     System.out.println("yell");
  }
}

public class Dog extends Animal { // java inheritance (extends)
  public static void main(String[] args) {
    Dog d = new Dog();
    d.yell();
  }
}

Output:

yell
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments