Please find the below code. Can any one tell me how Activator.CreateInstance Working with abstract class? I have created abstract class, in Abstract class have one abstract method and inheritted in normal three different classes. The class which I mentioned it is returned correct value, I want to know how its working? Thanks Advance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sample_App
{
abstract class ABSClass
{
public abstract int AddTwoNumbers();
}
class FirstClass : ABSClass
{
public override int AddTwoNumbers()
{
return 1 + 2;
}
}
class SecondClass : ABSClass
{
public override int AddTwoNumbers()
{
return 3 + 2;
}
}
class ThirdClass : ABSClass
{
public override int AddTwoNumbers()
{
return 3 + 2;
}
}
class Program
{
static void Main(string[] args)
{
Type ClassType = Type.GetType("Sample_App.FirstClass");
ABSClass obj = Activator.CreateInstance(ClassType) as ABSClass;
int i = obj.AddTwoNumbers();
}
}
}