This tutorial is explain about What is a Inheritance in Java and also explain about types of inheritance and explanation and given example of Java Programming.
Inheritance:- when create a child class that extended by the super class and the child class access all the features and properties of the super class is called a Inheritance. In Inheritance, we cannot access private members of super class.
Syntax :- There is defind class A that is super class and its statment inside this class body. There is anothere class declare class B its called a child class and Its statement inside this class. Accessing of super class A functions, variables and statments by the class B using extends keyword.
class A{
Statments;
}
class B extends class A{
Statements;
}
Type of Inheritance:-
1. Single level Inheritance
2. Multi level Inheritance
3. Multiple level Inheritance
4. Hierarchical Inheritance
1. Single level Inheritance:- In a single level Inheritance you define a super class A and child class B access all the properties and features of super class A. There is only one super class and a single child class use so this is called single level Inheritance.
class A{
Statements;
}
class B extends class A{
Statements;
}
2. Multi Level Inheritance:- In this inheritance you use super class A and this super class extends by child class B and access properties and features. After that child class C is extends by the super class B so class B is super class of class C and child class C access features and properties of class B. So this type of Inheritance is called multi Level Inheritance.
class A{
Statments;
}
class B extends class A{
Statements;
}
class C extends class B{
Statements;
}
3. Hierarchical Inheritance:- There is you define a super class and its features and properties use by more then one child class is called Hierarchical Inheritance.
Example:-
class A{
Statments;
}
class B extends class A{
Statements;
}
class C extends class A{
Statements;
}
4. Multiple Inheritance:- there is you define two super class and extends by single child class is called multiple Inheritance. For Example:-
class A{
Statements;
}
class B {
Statements;
}
class C extends class A, class B{
Statements;
}
Note:- Java is not supported the multiple Inheritance because of there is not clear so first remove ambiguity and provide a clear design its require a more maintaince.
0 Comments
Hello Friends, Please comment and share and do not write spam messages