Java Inheritance — Free Java Tutorial
Learn Java Inheritance in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Java Inheritance in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Java Inheritance in Java
Inheritance allows a class (child/subclass) to acquire the fields and methods of another class (parent/superclass). Use the `extends` keyword.
Polymorphism means "many forms" — a parent type reference can hold a child type object. The correct method is called at runtime based on the actual object type (dynamic dispatch).
The `super` keyword refers to the parent class. Use `super()` to call the parent constructor; use `super.method()` to call a parent method from the child.
Method overriding: a child class provides its own implementation of a method defined in the parent. Use `@Override` annotation to signal this intent.
Abstract classes (declared with `abstract`) cannot be instantiated directly. They serve as base classes and can have abstract methods (no body) that subclasses must implement.
Interfaces define a contract — a set of method signatures that implementing classes must provide. A class can implement multiple interfaces (unlike extends, which allows only one parent).
Java Inheritance — Syntax
// Parent class
public class Animal {
protected String name;
public Animal(String name) { this.name = name; }
public void speak() { System.out.println("..."); }
}
// Child class
public class Dog extends Animal {
public Dog(String name) { super(name); } // call parent constructor
Learn Java Inheritance step by step with Syllab's free interactive Java tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Java course →