![]() ![]() Reduces source code size and improves code readability.Īfter using this code is easy to manage and divided into parent and child classes. ![]() This type of implementation can also be called as Hierarchical Inheritance. "BaseClass".Īs you see that we have two derived classes implemented from same base class. Here you can see that above the code that base class "BaseClass" and two derived classes "childClass" and "SecondChildClass" which are implemented from same base class i.e. In short it means single base class having more than one derived classes. When we create a structure of project as like that where more than one derived classes are implemented from a same parent class or base class then that type of implantation is known as hierarchical inheritance. When you create a derived class which inherited from another derived class or in simple word if a class is created by using another derived class and this type of implementation is called as multilevel InheritanceĮxample of Multilevel Inheritance class ParentClassįrom the above source code you can see that we have achieved multilevel Inheritance by implementing one derived class to another derived class.Ĭ# does not support multiple inheritances due to the complexity of a code and it creates diamond structure which creates ambiguity. Here I am using single inheritance using single base class. ![]() Here only one parent class and one derived class.Įxample of Single Inheritance class ParentClassĬonsole.WriteLine("This is parent’s Run method") Ĭonsole.WriteLine("This is parent’s Walk method") Ĭonsole.WriteLine("This is the child’s Eat Method") Single Inheritance means there is a single base class which is implemented by single derived class is called as Single Inheritance. It is used when we create a class and we want to reuse some of the methods or properties from existing class then that is an right way to implement inheritance. We normally talk in terms of base class and derived class.īasic structure of Inheritance class ParentClass In Inheritance, Main class is called base class or super class or parent class and the new class created from existing class is called as child class or sub class or derived class. ![]() So when you use Inheritance you can reuse the code again and again. It also referred to as reusability of the code. Using Inheritance methodology you can create a new class by using existing class. Inheritance means acquiring the features and behaviors of a class by another class. I t is a parent-child relationship. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |