![]() |
VOOZH | about |
In C#, an abstract class is a class that cannot be instantiated directly. Abstract classes are used when we want to define a common template for a group of related classes but leave some methods or properties to be implemented by derived classes.
Example
The Cat goes Meow Walking like a cat... The Dog goes Woof Running like a dog...
Explanation:
abstract class gfg{}
// class 'gfg' is abstract
Example 1: Working of an abstract class.
class Child1 class Child2
Example 2: This example demonstrates abstract classes with both abstract and non-abstract methods, where the non-abstract method is inherited directly and the abstract method is overridden in the derived class.
Addition: 10 Multiplication: 24
Note: An abstract method is a method that is declared in an abstract class but has no body. Any non-abstract class that inherits the abstract class must provide the implementations for the abstract method.
Example 3: Program to calculate the area of a Square using abstract class and abstract method
Area = 36
Example 4: Abstract class can also work with get and set accessors.
5
Advantages
Disadvantages