Inheritance
extends inherits from a class. super calls the parent and @Override marks a replaced method.
Example
public class Main {
static class Animal { String sound() { return "..."; } }
static class Dog extends Animal { @Override String sound() { return "Woof"; } }
public static void main(String[] args) {
Animal a = new Dog();
System.out.println(a.sound());
}
}Result
Woof
Exercise
Subclass keyword.
class Dog Animal
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.