0% found this document useful (0 votes)
5 views1 page

Inheritance Examples2

The document explains the concept of inheritance in C# OOP, where a derived class is created from a base class to utilize common functionalities and attributes. It highlights that C# supports only single inheritance, meaning a derived class can only inherit from one base class. An example is provided with a base class 'polygon' and two derived classes 'rectangle' and 'parallelogram' demonstrating area calculations.

Uploaded by

ripohob417
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Inheritance Examples2

The document explains the concept of inheritance in C# OOP, where a derived class is created from a base class to utilize common functionalities and attributes. It highlights that C# supports only single inheritance, meaning a derived class can only inherit from one base class. An example is provided with a base class 'polygon' and two derived classes 'rectangle' and 'parallelogram' demonstrating area calculations.

Uploaded by

ripohob417
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]();

}
}

You might also like