INHERITANCE is the special feature of C# OOP that can create new class
from a class called based class by taking common funtionalities(methods) and
other attibutes of a based class.
DERIVED CLASSES:The new classes created by taking common
funtionalities(methods) and other attibutes of the based class are called
derived classes. C# supports only single Inheritance i.e. derived class can’t
create from more than only one based class.
Example:
using System;
using [Link];
using [Link];
public class polygon //base class
{
public int width;
public int height;
public void setvalues(int w, int h)
{
width = w;
height = h;
}
}
public class rectangle : polygon //[Link] class of polygon
{
public int arearectangle()
{
return (width * height);
}
}
public class parallelogram : polygon //[Link] class of polygon
{
public int areaparallelogram()
{
return (width * height);
}
}
public class Program
{
public static void Main(string[] args)
{
rectangle r=new rectangle();
parallelogram p=new parallelogram();
[Link](3,4);
[Link]("\n The area of rectangle:");
[Link]([Link]());
[Link](5,6);
[Link]("\n The area of parallelogram:");
[Link]([Link]());
[Link]();
}
}