Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

What is Hierarchial Inheritance in Java? With Examples

By Pavan Vadapalli

Updated on Dec 30, 2024 | 6 min read

Share:

Java is a popular programming language worldwide because of its versatility and compatibility. It finds crucial importance in various fields, including mobile applications, software development and the development of large systems. The mobile operating systems of 88% of the android phones were found to be written in Java in the year 2018. Learning and mastering this programming language opens a broader prospect of employment for the developers. 

Concept of Inheritance in Java:

Inheritance is a mechanism in Java in which an object gains all the properties and characteristics of a parent object. Object-oriented programming systems such as Java considers inheritance as one of the important concepts. The key principle behind the Java inheritance concept is that new classes can be built on the basis of the existing classes. The code blocks and methods of the parent class can be reused while inheritance is incorporated from an existing class. The addition of new fields and methods in a newly created class is also possible while a class is inherited. The inheritance in Java denotes the IS-A relationship that is commonly referred to as a parent-child relationship. Inheritance can be implemented in Java with the use of the keyword ‘extends’.

Note: Inheritance is used in Java to implement method overriding and hence ensure the accomplishment of runtime polymorphism. It can also be used to reuse the code.

Hierarchical Inheritance In Java: How Does It Work?

One superclass and a number of subclasses are included in Java’s hierarchy of inheritance. There must be at least two subclasses for inheritance to take place. When a superclass and numerous subclasses that will inherit from it exist, inheritance can function.

To allow for the flow of properties during inheritance, a superclass must be constructed first, followed by various subclasses. By doing this, the length of the code is drastically shortened, and inheritance improves the comprehension of the code. 

Hierarchical Inheritance in Java: Why Use It?

Code repetition is frowned upon in programming since it unnecessarily lengthens the code. It is required of a good programmer to produce code that is both reusable and clean. One technique that allows for extensive code reuse is hierarchical inheritance in Java.

In reality, one can go for a hierarchical inheritance program in Java to make it much easy and simpler to utilize a piece of code multiple times. So, let’s learn how hierarchical inheritance in Java works with an example. Let’s begin.

Check out our free technology courses to get an edge over the competition.

Important Terminologies used in Hierarchical Inheritance in Java:

1 .  Class:

A collection of objects with several properties that are common among them is referred to as a Class. It acts as a blueprint or a template for the creation of objects. 

2. Sub Class or Child Class:

A class that extends the other class is called a subclass. A subclass is also referred to as a child class or derived class or extended class. 

3. Super Class or Parent Class:

The class from which the features of the subclass are inherited is called a superclass. It is also called a parent class or a base class.

4. Reusability:

This is a property of the inherited class by virtue of which the fields and methods of a parent class can be reused in the newly created class. All the methods and fields used in the existing class can be used in the new class with this property.

Check out all the Trending Java Tutorial Topics in 2024.

Hierarchical Inheritance in Java

Inheritance is a mechanism in which a class or an object is dependent on another class or object to implement the same behavior of the class or object on which it depends. This permits independent extensions of the novel software via public interfaces and classes. It also helps in the mechanism of reusability of the code segments. If a hierarchical relationship exists between the classes or objects, it is referred to as the hierarchical inheritance. A single class serves as a parent class for several derived classes in the hierarchical inheritance.

Hierarchical inheritance in Java is a type of inheritance in which the same class is inherited by more than one class. In other words, when several classes inherit their features from the same class, the type of inheritance is said to be hierarchical. For example, consider 4 classes A, B, C and D, where A is the class from which B, C and D are inherited. 

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

Other kinds of Inheritance in Java:

Based on the class, there exist three inheritance types in Java. One of those is already discussed in the previous sections with sufficient example programs. Other than that, Java permits single and multilevel inheritances. In single inheritance, as indicated by the name, one class inherits only one class. i.e., there exists a single subclass for a parent class.  A class can inherit from an existing derived class in Multilevel inheritance. i.e., the base class of the newly formed class is a derived class. It is important to note that Java supports multilevel inheritance but not multiple inheritance. 

Limitations of Inheritance in Java:

With the use of inheritance, the parent class and the child class are closely coupled. If the code of the superclass is changed, the subclasses are also affected. So, the parent class and child class are dependent on each other. 

If you’re interested to learn more about Java, full-stack software development, check out upGrad & IIIT-B’s Executive PG Programme in Software Development – Specialisation in Full Stack Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Hierarchical Inheritance in Java Example: Real-World Example

Here is a Hierarchical Inheritance in Java example for a clearer understanding of how it works. Let’s say every employee in a company receives an average salary or payout of INR 30,000. Now, the interns are entitled to a 25% increase in this average payout and a 50% increase for the full-timers. Show the new salary structure upon the increment. 

Code: 

// parent class
class Employee {
 double salary = 30000;
 void displaySalary() {
   System.out.println("Employee Salary: Rs."+salary);
 }
}
// child class
class FullTimeEmployee extends Employee{
 double hike = 0.50;
 void incrementSalary() {
   salary = salary + (salary * hike);
 }
}
// child class
class InternEmployee extends Employee{
 double hike = 0.25;
 void incrementSalary() {
   salary = salary + (salary * hike);
 }
}
public class Main {
 public static void main(String[] args) {
   // object created
   FullTimeEmployee emp1 = new FullTimeEmployee();
   InternEmployee emp2 = new InternEmployee();
   System.out.println("Salary of a full-time employee before incrementing:");
   emp1.displaySalary();
   System.out.println("Salary of an intern before incrementing:");
   emp2.displaySalary();
   // salary incremented
   emp1.incrementSalary();
   emp2.incrementSalary();
   System.out.println("Salary of a full-time employee after incrementing:");
   emp1.displaySalary();
   System.out.println("Salary of an intern after incrementing:");
   emp2.displaySalary();
 }
}

The parent class Employee is constructed with the variable salary and function displaySalary() to address the aforementioned issue. 

After that, child classes are made using the appropriate raise percentage. The salary value is inherited from the Employee class and increased appropriately in the incrementSalary() function. The displaySalary() method that the parent class inherited is then used to display the salary. 

Output:

  • Full-timers’ salary before increment: INR 30,000
  • Interns’ salary before increment: INR 30,000
  • Full-timers’ salary after increment: INR 45,000
  • Interns’ salary after increment: INR 37,500

Conclusion

  • Hierarchical inheritance in Java is among the four foundational principles of OOPs or Object-Oriented Programming. 
  • Hierarchical inheritance in Java is a type of inheritance allowing multiple child classes to share and distribute the identical parent class’s properties and methods. 
  • Besides shortening the code and making it reusable, hierarchical inheritance in Java makes it more modular. 
  • It takes two or more subclasses that extend (or inherit) the same superclass for there to be hierarchical inheritance. 

Pavan Vadapalli

971 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

Suggested Blogs