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