0% found this document useful (0 votes)
65 views3 pages

Abstraction in C#

Abstraction is a process that involves identifying critical behaviors of an object and eliminating irrelevant details. It allows focusing on essential qualities without knowing internal complexities. The document provides an example of a laptop to illustrate abstraction - users interact without understanding internal components. It also provides a code example demonstrating abstraction in C# by defining an abstract university class with methods for degrees that are overridden in derived classes specifying fees. The output displays fees for degrees at different universities.

Uploaded by

Shahrukh Malik
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)
65 views3 pages

Abstraction in C#

Abstraction is a process that involves identifying critical behaviors of an object and eliminating irrelevant details. It allows focusing on essential qualities without knowing internal complexities. The document provides an example of a laptop to illustrate abstraction - users interact without understanding internal components. It also provides a code example demonstrating abstraction in C# by defining an abstract university class with methods for degrees that are overridden in derived classes specifying fees. The output displays fees for degrees at different universities.

Uploaded by

Shahrukh Malik
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
You are on page 1/ 3

Abstraction in C# with Example

In object-oriented software, complexity is managed by using abstraction. Abstraction is a process that involves
identifying the critical behavior of an object and eliminating irrelevant and complex denials. Abstraction is a
process of identifying the relevant qualities and behaviors an object should possess.

Example- A Laptop consists of many things such as processor, motherboard, RAM, keyboard, LCD screen,
wireless antenna, web camera, USB ports, battery, speakers etc. To use it, you don't need to know how
internally LCD screens, keyboard, web camera, battery, wireless antenna, speakers works. You just need to
know how to operate the laptop by switching it on.

Note- When derived class inherited with abstract class; derived class must be override abstract
class methods.

Example of Abstraction: using System;


using System.Collections.Generic;
using System.Linq;
namespace abstarction
{
public abstract class university
{
public abstract void BTech();
public abstract void MBA();
}
public class GBTU : university
{
public override void BTech()
{

Console.WriteLine("GBTU BTech Fee 50000/-");


}
public override void MBA()
{
Console.WriteLine("GBTU MBA Fee 100000/-");
}
}
public class MTU : university
{
public override void BTech()
{
Console.WriteLine("MTU BTech Fee 40000/-");
}
public override void MBA()
{
Console.WriteLine("MTU MBA Fee 800000/-");
}
}
class Program
{
static void Main(string[] args)
{
GBTU g = new GBTU();
g.BTech();

g.MBA();
MTU m = new MTU();
m.BTech();
m.MBA();
Console.ReadLine();
}
}
}

OutputGBTU BTech Fee 50000/GBTU MBA Fee 100000/MTU BTech Fee 40000/MTU MBA Fee 800000/-

Explanation : From above example we have make one abstract class university and two abstract
methods Btech and MBA. GBTU and MTUboth are override university course fee.
University course common for both GBTU and MTU so university method BTech and MBA is
abstract.
GBTU and MTU inherited abstract method so university method must be override here.

You might also like