All Classes in Java are Inherited From Which Class?

Learn via video course
FREE
View all courses
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Which Class is Inherited by all the Java Classes?

Object class is inherited by all the classes in Java. It is the parent class of every class in Java either directly or indirectly. Since it is the parent class of all classes, therefore, all its methods are available to all other classes in Java. Therefore, Object class behaves as a root of inheritance hierarchy in Java.

Since Java supports hierarchical inheritance, all the classes are directly or indirectly inherited from the Object class of Java. If a class does not extend any class then it will be directly linked to the Object class, that is, it becomes a direct child of the Object class. However, if a class is extending any other class then it forms an indirect link to the Object class. This is because multiple inheritance is not supported in Java. Hence, a class can either inherit the Object class or any other class but not both of them.

The Object class has many methods such as hashCode(), getClass(), toString() which are used by all the classes. Therefore, we do not need to again write these methods in our code, we can simply extend the Object class and use them in our class.

Examples

Inheritance is a mechanism in which a class acquires or inherits the properties of another class. Let us see some examples of inheritance in Java.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Terminologies Used

  • Parent class: The class whose properties are inherited is called the parent class, superclass or base class.
  • Child class or subclass or derived class: The class that inherits the properties of another class is called the child class, subclass or derived class.

There are various types of inheritance supported in Java as mentioned below:

  • Single Inheritance - In single level inheritance, a class inherits the properties of only one base class.
  • Multilevel Inheritance - In this type of inheritance, one subclass is derived from is superclass which is also derived from another superclass. Therefore, there are multiple parent classes of a single class.
  • Hierarchical Inheritance - If multiple sub classes are derived from a single base class then it is known as the hierarchical inheritance.
  • Hybrid Inheritance - Hybrid means more than one. Therefore, hybrid inheritance is a collection of two or more types of inheritance.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

IS-A Relationship

These two classes (superclass and subclass) involved in inheritance have a parent-child relationship which is also known IS-A relationship.

Let us understand this IS-A relationship concept with an example. Suppose you have a class Car and a class Audi. Since Audi is a Car, this relationship is true, therefore, the Car class can be inherited by the Audi class.

Java Inheritance

Single Level Inheritance

Single Level Inheritance refers to the scenario when a class inherits the properties from only one class. In single-level inheritance, there is only one level of inheritance which means the superclass does not inherit again from any other class.

There may be multiple subclasses inheriting from a single superclass but the superclass does not inherit from any other class.

Below is the code which shows the usage of single level inheritance.

Output:

Explanation:

In the above example, we have two classes - Parent and Child where the Child class inherits the Parent class. Here, the Parent class does not again from any other class, hence this is an example of Single Level Inheritance.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Multilevel Inheritance

Now let us understand, multilevel inheritance in Java. In multilevel inheritance, a derived class will be inherited from a base class and this class will also act as the base class for another derived class and so on.

Let us understand it with an example.

Output:

Explanation:

In the above example, Child1 class inherits from the Parent class, Child2 class inherits from Child1 class, whereas Child3 inherits from Child2. Therefore, all these classes make a hierarchy of classes.

Learn More

Various types of inheritance are explained in the article Inheritance in Java. You can refer to it to understand more about inheritance in Java.

Conclusion

  • All the classes in Java are inherited from the Object class. Object class is the parent class in Java.
  • All classes in Java directly or indirectly inherit the Object class.
  • Inheritance is an object-oriented concept in which one class uses the properties and behavior of another class.
  • There are various types of inheritance supported in Java such as:
    • Single Level inheritance
    • Multi-level inheritance
    • Hierarchical inheritance
    • Hybrid inheritance
  • Inheritance provides us with the feature of reusability.