3
Answers

Why we can't create object of Abstract class?

Mr Raj Anand

Mr Raj Anand

10y
10.7k
1
//An Abstract class may have public constructor but we can not able to create its object.

public
abstract class MyAbstract
{
   private int x;
   public MyAbstract(int p)
   {
      this
.x = p;
   }
}

public class MyClass : MyAbstract
{
   public MyClass(int p) : base(8)
   {
      p = 8;
   }
}

public class Hello
{
   MyAbstract abss = new MyClass(3);
   MyAbstract abss = new MyAbstract(4);
   MyClass cls = new MyAbstract(5);
}
In the above example last two line is not permissible.
Answers (3)
Next Recommended Forum