Saturday, November 26, 2016

single inheritance - Types Of Inheritance Classes

single inheritance - Types Of Inheritance Classes

       

         Define Single Multi-Inheritance & use

Inheritance is a pillar of OOP, in general term inheritance means parent child relationship. This same thing or same idea came up with Java programming. Suppose we have two classes (Class A and Class B). if Class B inherit the Class A or in simple word If Class B is the child of Class A, then Class B will access the all data and properties of It parent Class B.
Types Of Inheritance Classes

Inheritance showing a IS-A relationship means Class B IS-A Class A. because all properties and data of Parent Class A will be access by Child Class B, so that Child Class B having own properties and data members as we as Parent Class A properties and data members

Syntax:
class sub-class-name extends parent-class-name{

}
The extends keyword is used to inherit the parent class


Example:

aditionalJava
Types Of Inheritance Classes.

Types of Inheritance

In java there are five types of inheritance which are the following
o   Single
o   Multi-Level
o   Hierarchy
o   Multiple
o   Hybrid

Single
A single class inherit the parent class is known as Single Inheritance.

Multi-Level
When different Child classes inherit different Parent Classes and make a chain is known as Multi-Level Inheritance

Example

multiplicationLevel
Types Of Inheritance Classes.

Hierarchy

When different Child classes inherit the single Parent and showing hierarchical relationship is known as Hierarchy Inheritance

Example
HierarchyInhirtance

Note:

in hierarchy inheritance except main method class to access other class object you have to create their objects in main method Class.
Types Of Inheritance Classes

Multiple and Hybrid is not supported by Java programming basically because in Multiple and Hybrid Inheritance the single Child class try to access more than one parents, if we compare this concept with real world then you tell me it is possible that a single child having more than one father? Obviously No, this is illegal so that’s why Java basically cannot support Multiple and Hybrid Inheritance.

Note: Interface is only one thing which help to support Multiple and Hybrid inheritance in java. We learn this in Interface section

Types Of Inheritance Classes.





No comments:

Post a Comment