Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Hierarchical inheritance in java language

Posted on February 2, 2017December 27, 2019

Table of Contents

  • Hierarchical inheritance in java language
    • Related

Hierarchical inheritance in java language

In this tutorial, we will discuss the subject of Hierarchical inheritance in java language
Hierarchical inheritance is when multiple classes inherit from a single class. There are one parent (super) class and many children(sub) classes. Hierarchical inheritance is supported in Java. In the example below, class B, class C and class D inherit the properties of class A. Class A acts as the parent class of class B, class C and class D.
In the diagram above, a class can have more than one child class (subclasses) or two or more children classes can only have one (same) parent class. Here, Class A acts as the parent for subclasses class B, class C and class D. This is known as hierarchical inheritance.
Let’s try to understand using the following syntax

Syntax
class A
{
public void method_A
      {
//Block of code
      }
}
class_B extends class_A
{
public void method_A
      {
//Block of code
      }
}
class_C extends class_A
{
public void method_A
      {
//Block of code
      }
}
class MainClass{
public static void main(String args[]){
B obj1=new B();  // object created class B
obj1.method_A(); //call method_A() method of class B
obj1.method_B(); //call method_B() method of class B
C obj2=new C();  // object created class C
obj2.method_C(); //call method_C() method of class C
obj1.method_A(); //call method_A() method of class C
}
}
Example
Program 1
Program 2

 

Related Links
 
Inheritance in Java                        Inheritance in C++
 
Single level inheritance in java      Single level inheritance in C++
 
Multi levelinheritance in Java       Multilevel inheritance in C++
 
Interface in Java                            Multiple Inheritance in C++
Hybrid inheritance in C++

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes