Can u create the instance for abstract classes

Showing Answers 1 - 7 of 7 Answers

Rich

  • Jul 3rd, 2006
 

This is sort of a trick question. You can instantiate an instance of an Abstract class by using System.Activator.CreateInstance

  Was this answer useful?  Yes

Elina

  • Jul 9th, 2006
 

No, you cannot, it thows exception "System.MemberAccessException: Cannot create an abstract class"

  Was this answer useful?  Yes

Gaurav

  • Sep 26th, 2006
 

This is not working. Following is the code:

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

public abstract class sayhello

{

public void hello()

{

Console.WriteLine("hello");

}

}

class Program

{

static void Main(string[] args)

{

Object o=System.Activator.CreateInstance(typeof(sayhello));

((sayhello)o).hello();

}

}

}

Please clarify..

yunuskhan

  • Mar 4th, 2009
 

We can create an instance of an abstract class.

The below code is not working:

sayHello is an abstract class

Object o=System.Activator.CreateInstance(typeof(sayhello));

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions