In this article, I’m trying to
explain the concept of inheritance.
One of the most important
concepts in object-oriented programming is inheritance. Inheritance allows us
to define a class in terms of another class, which makes it easier to create
and maintain an application. This also provides an opportunity to reuse the
code functionality and fast implementation.
When creating a class, instead of
writing completely new data members and member functions, the programmer can
design that the new class should inherit the members of an existing class. This
existing class is called the base class, and the new class is referred to as the derived class.
class ClassName : baseclassname
Inheritance can be classified to 5 types:
when a single derived class is created from a
single base class then the inheritance is called as single inheritance.
when more than one derived class is created from
a single base class, then that inheritance is called as hierarchical
Multi Level Inheritance
when a derived class is created from another
derived class, then that inheritance is called as multi level inheritance.
Any combination of single, hierarchical and
multi level inheritances is called as hybrid inheritance.
when a derived class is created from more than
one base class then that inheritance is called as multiple inheritance. But
multiple inheritances are not supported by .net using classes and can be done
/// create a base class and a method in it
void add(int x, int y)
Console.WriteLine("Addition : " +(x+y));
class DerivedClass : BaseClass //inherit
/// create a derived class and a method in it
void multiply(int x, int y)
Console.WriteLine("Multiply ; "+(x*y));
void Main(string args)
DerivedClass dc = new DerivedClass();
// create a derived class object
dc.add(21,34); // call
base class method with derived class object
Addition : 55
Multiply : 20
In this example, I have created two classes – one base
class with method add() and derived class with method multiply(), derived class
inherits the base class , in class program – create the derived class object
and call the base class method add() and
derived class method multiply() with it and see the desired output.