Inheritance Keyword in Classes

Benjamin Jul 11, 2026

In the realm of object-oriented programming, inheritance is a fundamental concept that allows one class to acquire properties and methods of another. A key aspect of this process is the use of a specific keyword, which varies depending on the programming language. Let's delve into this topic, focusing on the keyword used to inherit a class in a few popular languages.

C# Base Class Keyword
C# Base Class Keyword

Before we dive into the keywords, let's briefly understand what inheritance is. Inheritance is a mechanism in which one class acquires the properties (methods and fields) of another. It sets up a 'is-a' relationship between classes, promoting code reuse and establishing a hierarchy.

a poster with the words and symbols for math keywords on it, which are in different colors
a poster with the words and symbols for math keywords on it, which are in different colors

Inheritance in Java

Java, a widely-used object-oriented language, employs the keyword 'extends' to denote inheritance. This keyword is used to create a subclass (or derived class) from a superclass (or base class).

Sealed Keyword in Scala
Sealed Keyword in Scala

Here's a simple example:

public class Animal {
  void eat() {
    System.out.println("eating");
  }
}

public class Dog extends Animal {
  void bark() {
    System.out.println("barking");
  }
}

In this snippet, 'Dog' is a subclass of 'Animal', inheriting the 'eat' method from the superclass.

Java Programming Tutorial 27- Inheritance, super keyword, Superclass Reference (IDE) (in English)
Java Programming Tutorial 27- Inheritance, super keyword, Superclass Reference (IDE) (in English)

Single Inheritance

Java supports single inheritance, meaning a class can extend only one superclass. However, it achieves multiple inheritance through interfaces.

Example:

Inheritance in Java
Inheritance in Java

public interface CanFly {
  void fly();
}

public class Bird extends Animal implements CanFly {
  public void fly() {
    System.out.println("flying");
  }
}

Method Overriding

Java allows subclasses to override methods of the superclass, providing their own implementation. This is done using the '@Override' annotation, although it's not mandatory.

Example:

Maths keywords
Maths keywords

public class Cat extends Animal {
  @Override
  void eat() {
    System.out.println("cat eating");
  }
}

Inheritance in Python

Python uses the keyword 'class' to define a class and the 'pass' keyword to define an empty class. Inheritance is denoted by placing the name of the superclass within parentheses in the subclass definition.

C# Interface with Example
C# Interface with Example
Common Coding Terms for Kids - UnicMinds
Common Coding Terms for Kids - UnicMinds
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
the words are in different languages for each subject to learn and use on this page
the words are in different languages for each subject to learn and use on this page
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!
High-Level Vocabulary for Competitive Exams | Advanced English Words
High-Level Vocabulary for Competitive Exams | Advanced English Words
Interface in Java programming language - Codeforcoding
Interface in Java programming language - Codeforcoding
Who would you be in my class? (short, easy quiz)
Who would you be in my class? (short, easy quiz)
Pinterest keywords
Pinterest keywords
✨Pinterest Keywords✨
✨Pinterest Keywords✨
a poster with the words and numbers for math keywords on it's side
a poster with the words and numbers for math keywords on it's side
C# Keywords Tutorial Part 66: protected
C# Keywords Tutorial Part 66: protected
vintage poster art!
vintage poster art!
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
pinterest keyword
pinterest keyword
a poster with words and pictures on it that says, upgrade your english learn to speak
a poster with words and pictures on it that says, upgrade your english learn to speak
different types of inerttances are shown on the whiteboard with red and blue lettering
different types of inerttances are shown on the whiteboard with red and blue lettering
Super Keyword In Java With Examples
Super Keyword In Java With Examples
a poster with different types of numbers and symbols on it's back side, including the
a poster with different types of numbers and symbols on it's back side, including the
the different types of symbols and their meanings
the different types of symbols and their meanings

Here's a Python example:

class Animal:
  def eat(self):
    print("eating")

class Dog(Animal):
  def bark(self):
    print("barking")

In Python, a class can inherit from multiple classes, demonstrating multiple inheritance.

Method Overriding in Python

Python also supports method overriding. The subclass provides its own implementation of a method that already exists in the superclass.

Example:

class Cat(Animal):
  def eat(self):
    print("cat eating")

Inheritance in C++

C++, another powerful object-oriented language, uses the keyword ':' to denote inheritance. It supports multiple inheritance, allowing a class to inherit from multiple classes.

Example:

class Animal {
public:
  void eat() {
    cout << "eating";
  }
};

class Dog : public Animal {
public:
  void bark() {
    cout << "barking";
  }
};

Access Specifiers in C++

C++ uses access specifiers (public, private, protected) to control the access to class members. In inheritance, the access specifier used with the superclass name determines the access level of the inherited members.

Example:

class Animal {
public:
  void eat() {
    cout << "eating";
  }
};

class Dog : protected Animal {
public:
  void bark() {
    cout << "barking";
  }
};

In conclusion, while the specific keyword used to inherit a class varies among programming languages, the concept of inheritance remains a cornerstone of object-oriented programming. It promotes code reuse, establishes a hierarchy, and facilitates the creation of complex, maintainable systems. Understanding and effectively using inheritance is crucial for any programmer looking to master object-oriented programming.