Inheritance makes programs simpler and faster. With inheritance, we build several types upon a common abstraction. Then we later act upon all those types through the abstraction. We examine inheritance and polymorphism in the C# language.
Base class:The class another class inherits from. In the C# language, the ultimate base class is the object class.
Object
Derived class:The class with a base class. A derived class may have multiple levels of base classes.
Example. When you specify that a class derives from another class, the class you create acquires all the features of the base class. If the derived class has a few extra features but is otherwise the same as the base class, this is a good approach.
Also:By using a base class, you can treat derived classes as the same base type and call virtual functions to access their features.
Program using base class, virtual method: C# using System; using System.Collections.Generic; class Net { public virtual void Act() { } } class Perl : Net { public override void Act() { Console.WriteLine("Perl.Act"); } } class Python : Net { public override void Act() { Console.WriteLine("Python.Act"); } }
There are different types of inheritance in c#.net
and these are:-
1)single inheritance.
2)multilevel inheritance.
3)hierarchical inheritance.
4)hybrid inheritance.
5)multiple inheritance.
multiple inheritance and hybrid inheritance not support in c#.
so we use interface.
No comments:
Post a Comment