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

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

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes