Introduction
In this article, I am going to explain abstract classes and abstract methods. With the help of abstraction we can achieve dynamic polymorphism i.e. the same method name in different classes but the same signature.
Abstract class
If a class is defined as abstract then we can't create an instance of that class. By the creation of the derived class object where an abstract class is inherit from, we can call the method of the abstract class.
Let's take an example: First of all, select a console application as follows:

and our code window looks like,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13 {
abstract class mcn {
public int add(int a, int b) {
return (a + b);
}
}
class mcn1: mcn {
public int mul(int a, int b) {
return a * b;
}
}
class test {
static void Main(string[] args) {
mcn1 ob = new mcn1();
int result = ob.add(5, 10);
Console.WriteLine("the result is {0}", result);
}
}
}
In the above program we can call the method of the abstract class mcn with the help of an object of the mcn1 class which inherits from the class mcn. When we run the above program the output is the addition of 5 & 10 (i.e. 15) which is shown as,

Abstract method
An Abstract method is a method without a body. The implementation of an abstract method is done by a derived class. When the derived class inherits the abstract method from the abstract class, it must override the abstract method. This requirment is enforced at compile time and is also called dynamic polymorphism.
The syntax of using the abstract method is as follows:
<access-modifier>abstract<return-type>method name (parameter)
The abstract method is declared by adding the abstract modifier the method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14 {
abstract class test1 {
public int add(int i, int j) {
return i + j;
}
public abstract int mul(int i, int j);
}
class test2: test1 {
public override int mul(int i, int j) {
return i * j;
}
}
class test3: test1 {
public override int mul(int i, int j) {
return i - j;
}
}
class test4: test2 {
public override int mul(int i, int j) {
return i + j;
}
}
class myclass {
public static void main(string[] args) {
test2 ob = new test4();
int a = ob.mul(2, 4);
test1 ob1 = new test2();
int b = ob1.mul(4, 2);
test1 ob2 = new test3();
int c = ob2.mul(4, 2);
Console.Write("{0},{1},{2}", a, b, c);
Console.ReadLine();
}
}
}
In the above program, one method i.e. mul can perform various functions depending on the value passed as parameters by creating an object of various classes which inherit other classes. Hence we can acheive dynamic polymorphism with the help of an abstract method.
NOTE
When we use an override keyword the preference will be given to classes which has an instance created; in case of inheritance, the preference will provide to the reference variable class.

KeithK KatanePosted Aug 11, 2020, 12:26 AM
Wouldn't the return statement in line 08 of example 1 be considered the body of the method?
Former memberPosted Aug 3, 2020, 11:13 PM
Rofl who is the dumb sob who posted this crapola
Artyom TimeyevPosted Nov 23, 2019, 4:59 AM
Thank you! A minor typo: the Main method should start with an uppercase M.
Lalesh YagysainiPosted Oct 29, 2018, 6:15 AM
What about virtual method that also has to be overridden we can achieve same so whats diffrence
Mahmod Abu JehadPosted Feb 6, 2018, 10:12 AM
Thx u so much, it's a hopefully , thx thx thx
Ken VanCampPosted May 24, 2017, 11:48 AM
Very very nice explanation. It is so nice to see someone present concepts in a simple straightforward manner. Too many people make things harder then they need to be.
Prasad JoshiPosted Feb 20, 2017, 8:04 AM
Just wow.. Concepts clear.. Thanks
SubashPosted Nov 6, 2016, 3:55 AM
Nice share helpful article
Former memberPosted Jul 1, 2016, 5:19 AM
Nice thanks for share
Kapil GuptaPosted Oct 15, 2013, 8:54 AM
what is the need of override keyword..?