Home > DeveloperSection > Blogs > Concept of Inheritance

Concept of Inheritance


C# C# 
Ratings:
0 Comment(s)
 1822  View(s)
Rate this:


Inheritance:


In object-oriented programming, inheritance is the concept that when a class of objects is defined, any subclass that is defined can inherit the definitions of one or more general classes. This means for the programmer that an object in a subclass need not carry its own definition of data and methods that are generic to the class (or classes) of which it is a part. This not only speeds up program development; it also ensures an inherent validity to the defined subclass object (what works and is consistent about the class will also work for the subclass).

Sometimes base class known as generalized class and derived class known as specialized class.

Example:

Class x

{

    Public static int add (int a,int b)

    {

        Return (a+b);

    }

}

Class y:X

{

    Public static int mul(inta,intb)

    {

        Return(a*b);

    }

}

Static void main()

{

    X obj=new y();

    Obj.add(5,6);

}


Don't want to miss updates? Please click the below button!

Follow MindStick