Java Class Inheritance: Keyword to Use

Benjamin Jul 11, 2026

In the realm of object-oriented programming, inheritance is a fundamental concept that allows classes to acquire properties and methods from other classes. In Java, this is achieved using a specific keyword. But which one?

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

Before diving into the keyword, let's briefly understand why inheritance is crucial. It promotes code reusability, establishes 'is-a' relationships, and enables polymorphism. Now, let's find out how to inherit a class in Java.

What is the Difference Between Abstract Class and Interface in Java - Pediaa.Com
What is the Difference Between Abstract Class and Interface in Java - Pediaa.Com

The Keyword: 'extends'

The keyword you're looking for is 'extends'. It's used to indicate that a class is inheriting from another class.

Horizon Expanded! Elite Python, Java, JS Help: Beyond the Search – Order for Expansive Excellence!
Horizon Expanded! Elite Python, Java, JS Help: Beyond the Search – Order for Expansive Excellence!

Here's a simple syntax to illustrate this:

```java class ParentClass { // properties and methods } class ChildClass extends ParentClass { // properties and methods } ```

Using 'extends' for Inheritance

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

In the example above, 'ChildClass' is inheriting from 'ParentClass'. This means 'ChildClass' can access all the public and protected properties and methods of 'ParentClass'.

Here's a simple example:

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

Inheriting Constructors

the key words in this language are used to describe something
the key words in this language are used to describe something

Java also allows you to inherit constructors using the 'super' keyword. This is useful when you want to call a parent class constructor from a child class.

Here's an example:

```java class Parent { Parent() { System.out.println("Parent constructor"); } } class Child extends Parent { Child() { super(); // Calling parent constructor System.out.println("Child constructor"); } } ```

Inheritance and Access Modifiers

Java List of Keywords (All Reserved Words) | Complete Java Reference Guide
Java List of Keywords (All Reserved Words) | Complete Java Reference Guide

Inheritance in Java is subject to access modifiers. A child class can only access the public and protected members of its parent class.

Here's a quick rundown:

Inheritance in Java Explained | OOP Concepts for Beginners
Inheritance in Java Explained | OOP Concepts for Beginners
What is Inheritance in Java with example - Object Oriented Programming Tutorial
What is Inheritance in Java with example - Object Oriented Programming Tutorial
online help: interface in java - online help
online help: interface in java - online help
Inheritance in Java
Inheritance in Java
What is Inheritance in Java – 5 Types, Use and Advantages
What is Inheritance in Java – 5 Types, Use and Advantages
Java Programming
Java Programming
Super Keyword In Java With Examples
Super Keyword In Java With Examples
know java extends keyword with examples
know java extends keyword with examples
http://chatgpt.com/g/g-lvtjtj09i-darkhorse-dns
http://chatgpt.com/g/g-lvtjtj09i-darkhorse-dns
Keywords in Java - Java Reserved Words - TechVidvan
Keywords in Java - Java Reserved Words - TechVidvan
Java Class Inheritance
Java Class Inheritance
10 Examples of Inheritance in Java 🔗
10 Examples of Inheritance in Java 🔗
Constructor in Inheritance and Super keyword in JAVA || JAVA Tutorial in Hindi #26 || Death Code
Constructor in Inheritance and Super keyword in JAVA || JAVA Tutorial in Hindi #26 || Death Code
30 Days of Java – Day 14 | Java Inheritance Explained for Beginners
30 Days of Java – Day 14 | Java Inheritance Explained for Beginners
Java Keywords
Java Keywords
🔥 Java Super Keyword Explained! 🚀
🔥 Java Super Keyword Explained! 🚀
Java Programming Tutorial 27- Inheritance, super keyword, Superclass Reference (IDE) (in English)
Java Programming Tutorial 27- Inheritance, super keyword, Superclass Reference (IDE) (in English)
Java Class and Objects - Easy Learning with Real-life Examples! - TechVidvan
Java Class and Objects - Easy Learning with Real-life Examples! - TechVidvan
30 Days of Java – Day 12 | Java Classes and Objects Explained for Beginners
30 Days of Java – Day 12 | Java Classes and Objects Explained for Beginners
Java Inheritance - Learn its Importance and Types with Coding Examples.
Java Inheritance - Learn its Importance and Types with Coding Examples.
  • Public: Accessible everywhere, including child classes.
  • Protected: Accessible within the same package and subclasses, even in other packages.
  • Default (no modifier): Accessible within the same package.
  • Private: Only accessible within the same class.

Protected Access Modifier

The 'protected' access modifier is particularly useful in inheritance. It allows child classes to access the parent's methods and properties, even if they're in different packages.

Here's an example:

```java // In package1 class Parent { protected void display() { System.out.println("Parent display"); } } // In package2 class Child extends Parent { void test() { display(); // Accessing protected method } } ```

In conclusion, the keyword to inherit a class in Java is 'extends'. It's a powerful tool that enables code reusability and establishes relationships between classes. As you delve deeper into Java programming, you'll find inheritance to be an essential concept that unlocks the full potential of object-oriented programming.