Java Class Inheritance Keyword

Benjamin Jul 11, 2026

In the vast landscape of object-oriented programming, Java offers a robust set of tools for class inheritance. Understanding the keywords used to inherit a class in Java is fundamental to leveraging the power of inheritance for code reusability and polymorphism. Let's delve into the key keywords: extends, implements, and their nuances.

10 Example of this keyword in Java
10 Example of this keyword in Java

Inheritance in Java allows one class to acquire the properties and methods of another. This relationship is established using the keywords extends and implements. Before we dive into these, let's briefly discuss the concept of interfaces, which play a crucial role in Java's inheritance model.

Inheritance in Java
Inheritance in Java

Inheritance in Java

Inheritance in Java is primarily achieved using the extends keyword. When a class extends another, it inherits all the non-private fields and methods of the parent class. This includes both instance variables and methods.

Super Keyword in Java: Syntax, Uses and Examples - Scientech Easy
Super Keyword in Java: Syntax, Uses and Examples - Scientech Easy

However, it's important to note that a class can only extend one other class (single inheritance). This is where interfaces come into play, allowing a class to implement multiple interfaces, thereby achieving a form of multiple inheritance.

Extends Keyword

The new keyword in Java programming language - Codeforcoding
The new keyword in Java programming language - Codeforcoding

The extends keyword is used to create a subclass (or derived class) from a superclass (or base class). The subclass inherits all the non-private fields and methods of the superclass. Here's a simple example:

```java public class Animal { public void eat() { System.out.println("Eating"); } } public class Dog extends Animal { public void bark() { System.out.println("Barking"); } } ```

In this example, the Dog class extends the Animal class, inheriting the eat method.

Implements Keyword

What is Inheritance in Java with example - Object Oriented Programming Tutorial
What is Inheritance in Java with example - Object Oriented Programming Tutorial

The implements keyword is used to implement interfaces. An interface is a completely abstract class that contains only abstract methods (no method bodies). A class can implement multiple interfaces, providing a way to achieve multiple inheritance in Java.

When a class implements an interface, it must provide implementations for all the methods declared in the interface. Here's an example:

```java public interface Flyable { void fly(); } public class Bird implements Flyable { public void fly() { System.out.println("Flying"); } } ```

In this example, the Bird class implements the Flyable interface, providing an implementation for the fly method.

Types of Inheritance in Java: A Comprehensive Guide
Types of Inheritance in Java: A Comprehensive Guide

Inheritance vs. Implementation

While both extends and implements are used for inheritance, they serve different purposes. The extends keyword is used for class inheritance, while the implements keyword is used for interface implementation.

🔥 Java Super Keyword Explained! 🚀
🔥 Java Super Keyword Explained! 🚀
the key words in this language are used to describe something
the key words in this language are used to describe something
Inheritance in Java Explained | OOP Concepts for Beginners
Inheritance in Java Explained | OOP Concepts for Beginners
Types of Inheritance in Programming
Types of Inheritance in Programming
Java List of Keywords (All Reserved Words) | Complete Java Reference Guide
Java List of Keywords (All Reserved Words) | Complete Java Reference Guide
the different types of children's names and their meanings are shown in this diagram
the different types of children's names and their meanings are shown in this diagram
10 Examples of Inheritance in Java 🔗
10 Examples of Inheritance in Java 🔗
Java Class Inheritance
Java Class Inheritance
Java Exception Handling Made Simple
Java Exception Handling Made Simple
What is Inheritance in Java – 5 Types, Use and Advantages
What is Inheritance in Java – 5 Types, Use and Advantages
Sorting ArrayList in Java using Collections.sort() Method
Sorting ArrayList in Java using Collections.sort() Method
Data Types in Java
Data Types in Java
a poster with the words in red and black, including an image of a man's face
a poster with the words in red and black, including an image of a man's face
Exception Handling in Java | Try Catch Finally Explained with Example
Exception Handling in Java | Try Catch Finally Explained with Example
Static Keyword In Java : All Scenarios
Static Keyword In Java : All Scenarios
Top Features of Java Every Beginner Should Know ☕🚀
Top Features of Java Every Beginner Should Know ☕🚀
three types of variable type in an organization
three types of variable type in an organization
Java Basic Syntax – Identifiers, Modifiers, Variables, Arrays, Enums
Java Basic Syntax – Identifiers, Modifiers, Variables, Arrays, Enums
Java Data Types Explained
Java Data Types Explained
Keywords in Java - Java Reserved Words - TechVidvan
Keywords in Java - Java Reserved Words - TechVidvan

Moreover, a class can only extend one other class, but it can implement multiple interfaces. This allows for a more flexible and powerful inheritance model in Java.

Inherits Keyword (Deprecated)

Java also had a third keyword, inherits, which was used in earlier versions for class inheritance. However, this keyword is now deprecated and its use is strongly discouraged. The recommended way to achieve inheritance is by using the extends keyword.

Here's an example of the deprecated usage:

```java public class Animal { public void eat() { System.out.println("Eating"); } } public class Dog inherits Animal { public void bark() { System.out.println("Barking"); } } ```

While this syntax was valid in earlier versions of Java, it's now considered outdated and should be avoided.

Understanding these keywords is crucial for any Java developer. They form the backbone of Java's object-oriented programming model, enabling code reusability, polymorphism, and multiple inheritance through interfaces. As you continue your Java journey, remember to leverage these tools to create efficient, maintainable, and extensible code.