0% found this document useful (0 votes)
42 views2 pages

C# Abstract Class: For Example

Abstract classes in C# allow for abstraction by hiding internal details and exposing only functionality. Abstract methods within an abstract class must be declared without a body and implemented in derived classes using the override keyword. An abstract class can contain constructors, destructors, and non-abstract methods, but cannot be inherited by structures and must have abstract methods implemented in child classes.

Uploaded by

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

C# Abstract Class: For Example

Abstract classes in C# allow for abstraction by hiding internal details and exposing only functionality. Abstract methods within an abstract class must be declared without a body and implemented in derived classes using the override keyword. An abstract class can contain constructors, destructors, and non-abstract methods, but cannot be inherited by structures and must have abstract methods implemented in child classes.

Uploaded by

Akshay Pawar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C# Abstract class

• Abstract classes are the way to achieve abstraction in


C#. Abstraction in C# is the process to hide the internal
details and showing functionality only.
• A method which is declared abstract and has no body is
called abstract method. It can be declared inside the
abstract class only. Its implementation must be
provided by derived classes.
• A user must use the override keyword before the
method which is declared as abstract in child class,
the abstract class is used to inherit in the childclass.
An abstract class cannot be inherited by structures. It
can contains constructors or destructors. It can
implement functions with non-Abstractmethods.
• SYNTEX
public abstract void method();

FOR EXAMPLE
using System;
public abstract class Shape
{
public abstract void draw();
}
public class Rectangle : Shape
{
public override void draw()
{
Console.WriteLine("drawing rectangle...");
}
}
public class Circle : Shape
{
public override void draw()
{
Console.WriteLine("drawing circle...");
}
}
public class TestAbstract
{
public static void Main()
{
Shape s;
s = new Rectangle();
s.draw();
s = new Circle();
s.draw();
}
}
Output:

drawing ractangle...
drawing circle...

You might also like