Today, we will learn about Abstract Class. Let’s start!!!
A class defined with Abstract keyword is simply Abstract Class. In simple words, we can say that a class especially designed to act as a base class for a number of classes is known as Abstract Class. Let’s take an example.
- static void Main(string[] args) {
- Person person = new Punjabi();
- Console.WriteLine("/*************Punjabi**************/");
- person.ICanSpeak();
- Console.WriteLine("\n");
- person.ICanWalk();
- person = new Tamil();
- Console.WriteLine("\n/*************Tamil**************/");
- person.ICanSpeak();
- Console.WriteLine("\n");
- person.ICanWalk();
- Console.ReadKey();
- }
- public abstract class Person {
- public void ICanWalk() {
- Console.Write("I can walk.");
- }
- public abstract void ICanSpeak();
- }
- public class Punjabi: Person {
- public override void ICanSpeak() {
- Console.Write("I can speak Punjabi.");
- }
- }
- public class Tamil: Person {
- public override void ICanSpeak() {
- Console.Write("I can speak Tamil.");
- }
- }

Some facts about Abstract Class.
- In an abstract class, we can define abstract method as well as non abstract methods.
- If we want to define an abstract method in abstract class, then we have to declare the method in abstract class without implementation. The declared abstract method must be implemented in derived class.

- We can’t instantiate the abstract class i.e. we can’t create object of abstract class.
- An abstract class can’t be sealed.
- We can inherit one abstract class into another abstract class. In that case, it is optional in the child class to implement the abstract method of base class. Let’s take an example.


The output will be same in both the cases.
- An abstract class can’t be sealed because a sealed class is the last class in the inheritance hierarchy, and abstract classes are designed to act as base class.
- Abstract class can have constructor as well as destructor.

Aravind SelvarajPosted Sep 29, 2016, 2:59 AM
Nice
Satish Kumar VadlavalliPosted Sep 19, 2016, 11:23 PM
Nice share :)
Bhuvan PandeyPosted Sep 6, 2016, 6:24 AM
Good work
SubashPosted Sep 5, 2016, 9:58 PM
Good
Lokesh KumarPosted Sep 5, 2016, 7:44 AM
Thanks For Sharing , It i helps me lot