Abstract Class in C#

6 Sept 2025 | 8 min read

C# abstract classes provide a strong means of defining a template for other classes, enforcing method implementation by providing the shared code. Abstract classes are employed where we need to create a common template for a class family, which allows derived classes to implement certain methods or properties. They are typically used to specify a general structure or behavior common to several derived classes without precluding those derived classes from presenting their particular implementations.

In C#, an abstract class is a class that is declared abstract. It can have abstract and non-abstract methods. It contains several fields, constructors, and methods. It cannot be instantiated directly. Its implementation must be provided by derived classes. Here, the derived class is forced to provide the implementation of all the abstract methods.

Syntax

It has the following syntax:

In this syntax,

  • abstract class ClassName: It represents the name of the abstract class, which means that it cannot be instantiated directly.
  • return_type: It represents the return type of the abstract method.
  • NormalMethod: It represents the body that performed the implementation.

C# Abstract Class Example

Let us take an example to illustrate the abstract class in C#.

Output:

drawing rectangle...
drawing circle...

Explanation:

In this example, we declare an abstract class Shape with an abstract method draw(). After that, we take the Rectangle and Circle classes that extend Shape and implement their draw(). In the main() method, a Shape reference is used to call draw() on both Rectangle and Circle objects, which prints out their respective messages.

C# Abstract Class Example with Constructors for Initialization

Let us take another example to illustrate the abstract classes in C# using Constructors.

Output:

Name: Johnson
Salary: 25000
Name: Michael
Salary: 30000

Explanation:

In this example, we have taken a class Employee that acts as a base class, which contains several common properties and methods. After that, we take two derived classes, Emp1 and Emp2, that set different names and salaries using constructors and override the abstract method EmpName. At runtime, every detail of the employee is displayed, which shows the shared common functionality of abstract classes while enabling specific implementations.

Abstract Method

A method that is declared abstract and has no body is called an abstract method. It can be declared inside the abstract class only. Its implementation must be provided by derived classes.

Syntax:

It has the following syntax:

In this syntax,

  • Access-modifier: It represents the visibility of the abstract method.
  • Abstract: It is used to define the method as abstract.
  • Return-type: It is used to define the data type that the method should return.
  • MethodName: It represents the abstract method name.

An abstract method in C# is internally a virtual method, so it can be overridden by the derived class. We cannot use static and virtual modifiers in an abstract method declaration.

C# Abstract Method Example

Let us take an example to illustrate the abstract method in C#.

Output:

Cat says: Meow! Meow!
Cat is drinking milk.

Explanation:

In this example, we take an abstract class Animal with two abstract methods Speak() and Drink(), which has no body. After that, the Cat class is inherited from Animal and overrides both methods with its implementation. In the main() function, an Animal reference is used to a Cat object, and invoking Speak() and Drink() invokes the overridden methods, which demonstrate the Cat's behavior.

C# Abstract Method Example for Bank Account Details

Let us take an example to illustrate the abstract method for Bank Account Details in C#.

Output:

600Rs deposited in Savings Account.
300Rs withdrawn from Savings Account.
Total Balance: 2100

Explanation:

In this example, we have taken an abstract class that defines the structure for a bank account with two abstract methods, Deposit and Withdraw. After that, we take a derived class SavingsAcc that gives concrete implementations of these methods to handle deposits and withdrawals. In the main method, we create an object of the SavingsAcc class where we make transactions and show the updated balance.

Usage of Abstract Class in C#

Several uses of abstract class in C# are as follows:

  • We can create multiple versions of the component because versioning is not a problem when dealing with abstract classes.
  • We can add properties or methods to an abstract class without recompiling, and all the inheriting classes are updated with the change automatically.
  • It is required to supply default behaviors along with general behaviors that several derived classes will have in common and be able to override.

Difference between Abstract Class and Interface

There are several main differences between an Abstract Class and an Interface in C#. Some main differences are as follows:

FeaturesAbstract ClassInterface
DefinitionAbstract class is a partially implemented class that defines both what and how a class should perform operations.An interface is a contract that defines only method signatures, properties, events, and indexers, but it has no implementation.
InstantiationIt cannot be instantiated.It cannot be instantiated.
Access ModifiersIt uses all access modifiers.It doesn't use an access modifier because all classes are public by default.
MembersIt contains several fields, constructors, and methods.It contains only method signatures, events, properties, and indexers.
InheritanceIt uses only single inheritance.It can implement multiple inheritance.
ImplementationIt can provide a default implementation.It has no implementation.

Benefits of Abstract Class in C#

There are several benefits of the abstract class in C#. Some of them are as follows:

  • Promotes code reusability: Abstract classes enable us to specify common behavior, methods, and properties that may be shared by many derived classes.
  • Acts as a template for derived classes: These are a template or blueprint for derived classes.
  • Supports inheritance and polymorphism: Abstract classes allow polymorphism so that derived classes can be viewed as instances of the abstract class.
  • Specifies contracts using abstract methods: Abstract classes specify contracts using abstract methods, which are implemented by derived classes.
  • Supports code modularization and organization: Abstract classes allow code to be organized and support modularity.
  • Allows extensibility in the future: Abstract classes are meant to be extended by derived classes.

Disadvantages of Abstract Class in C#

There are several disadvantages of the abstract class in C#. Some of them are as follows:

  • Tight coupling: Abstract classes introduce an element of coupling between the base abstract class and its subclasses. It suggests that changes to the abstract class could impact all subclasses.
  • Incomplete implementation: Abstract classes usually contain abstract methods, which need to be implemented in their derived classes.
  • Limited flexibility: When an abstract class is declared, its struct and contracts become more rigid than those of interfaces.
  • Object-oriented design issues: In certain situations, abstract classes can break some of the principles of object-oriented design, including the Single Responsibility Principle (SRP) or the Interface Segregation Principle (ISP).

Conclusion

In conclusion, the C# abstract class serves as a base template that can contain both fully implemented members and abstract members that lack a body. Subclasses are required to implement the abstract members. Abstract classes cannot be instantiated directly, which makes them ideal for providing common functionality while ensuring that certain methods are implemented in the subclasses.

Abstract Class FAQs

1) Can an abstract class contain constructors?

Yes, an abstract class may contain constructors. They are invoked when an object of a derived class is created to initialize base class members.

2) Can an abstract class include non-abstract members?

Yes, it may include both abstract (without body) and non-abstract (with body) members. It allows us to mix common implementation with forced overrides.

3) When should we use Abstract Classes rather than Interfaces?

Abstract classes are used to implement common functionality or provide a base version that can be extended by derived classes. On the other hand, interfaces are useful when we only want to define a contract for functionality without implementing anything.

4) Can we instantiate an object of an abstract class?

No, we cannot directly create an instance of an abstract class. We can create objects of derived classes only that must implement all abstract members.

5) How do an interface and an abstract class differ in C#?

The main difference between an interface and an abstract class in C# is as follows:

Abstract class: It can include both implemented and abstract members, has support for fields, and access modifiers are allowed.

Interface: It has only declarations, has no fields, and all members are public by default.


Next TopicC# Interface