Abstract class in Dot Net

Abstract keyword can be used with both classes and methods in C#. We can’t initialize the Abstract classes. But another class can inherit from an Abstract class and can create their instances.

Here is the example which is an abstract class but non abstract method,


using System;
using System.Collections.Generic;
using System.Text;
namespace testWinApp
{
public class AbstractTest:abstTesting
{
}
public abstract class abstTesting
{
public void myAbstract()
{
Console.Write("Abstract Test");
}
}
}


private void button1_Click(object sender, EventArgs e)
{
AbstractTest a = new AbstractTest();
a.myAbstract();
}

No comments: