A few important points to remember about an abstract class are given below.
- Abstract class cannot be directly instantiated but it can be instantiated through the base class object by type casting to it.
- Abstract class must contain at least one abstract method, which has no definition.
Now, let us see with the code snippets given below.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace AbstractclassDemo {
- class MyProgram {
- abstract class A {
-
- public abstract void show();
- public void disp() {
- Console.WriteLine("Display My Information");
- }
- }
- class B: A {
- public override void show() {
- Console.WriteLine("show");
- }
- }
- class Test {
- static void Main(string[] args) {
-
- B b = new B();
- A a = (A) b;
-
- a.disp();
- Console.Read();
- }
- }
- }
- }
- }