OOPS Principles are abstraction,inheritance,polymorphism these are basic points for oops.Inheritance is the most important and extraordinary topic.We are Providing Basic Information about Inheritance and also give datailed explanation about Types of Inheritance.
Brief Description About Inheritance
Inheritance Real Time Example |
Introduction about Inheritance
- Inheritance is nothing but deriving (or)inheriting the members from one class to another class.
- A class which is giving the members is called as super class (or) parent class(or) base class
- A class which is retrieving the numbers is called as sub class (or)derived class (or) child class
- Because of inheritance sub class can access super class members as well as using sub class objects we can access super class members.
- Because of inheritance super class cannot access subclass members as well as using super class object we cannot access subclass members.
Types Of Inheritance
Types Of Inheritance |
1.Single level inheritance
2.Multilevel inheritance
3.Multipel inheritance
4.Hybrid inheritance
5.Hierarical inheritance
1.Single Level Inheritance
Inheriting from one class to another class is called Single inheritance
Syntax:
class C1
{
}
class C2:C1
{
}
2.Muli Level Inheritance
Inheriting fromone class to another class,from that class to some other class is called is called as Multilevel inheritance.
Syntax:
class C1
{
}
class C2:C1
{
}
class C3:C2
{
}
3.Multiple Inheritance
inherting multiple classes into single class is called as multiple inheritance.
Syntax:
class C1
{
}
class C2
{
}
class C3:C2,C1
{
}
4.Hybrid Inheritance
A combination of two inheritance is nothing but Hybrid inheritance5.Hierarical Inheritance
Inheritating single class into multiple classes is called as Hierarichal inheritance
Syntax:
class C1
{
}
class C2:C1
{
}
class C3:C1
{
}
Advantages Of Inheritance
Code Reusability
Reusability
Because of inheritance a method which is defined in the super class can be accessed by derived classes by derived classes.That means here we are achieving code reusability with inheritance.
Friends You Like My Post Please Share in Facebook,Twitter,Google+.You Feel Free Comment On My Post.
0 comments:
Post a Comment