ABSTRACT CLASS IN C#

An Abstract class is an incomplete class or special class we can't instantiate. We can use an Abstract class as a Base Class. An Abstract method must be implemented in the non-Abstract class using the override keyword. After overriding the abstract method is in the non-Abstract class. We can derive this class in another class and again we can override the same abstract method with it.

The purpose of abstract class is to provide default functionality to its sub classes.

When a method is declared as abstract in the base class then every derived class of that class must provide its own definition for that method.

An abstract class can also contain methods with complete implementation, besides abstract methods.

When a class contains at least one abstract method, then the class must be declared as abstract class.

It is mandatory to override abstract method in the derived class.

When a class is declared as abstract class, then it is not possible to create an instance for that class. But it can be used as a parameter in a method.

Features:

1.An abstract class can inherit from a class and one or more interfaces.

Output :-

Enter Length=12

Enter width=9

Area Of Rectangle=108

Circumference=42

In this example, I have declared an abstract class with two abstract methods – area() and circumference(). Rectangle class inherits the abstract class and gives the definition to the abstract methods. In program class create object of rectangle class and call both the methods.

Modified On Sep-18-2014 01:24:12 PM

0 Comments

Leave Comment

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!