As all textbooks on C# will tell you, you cannot instantiate an abstract class.
I believe the keyword abstract was intended for that purpose.
So can anyone tell me why I can do something like this:

abstract class TwoDShape
{
    // some code here
}

class test
{
    static void Main()
    {
        TwoDShape shape = new TwoDShape(); // this gives an error
        TwoDShape[] shapes = new TwoDShape[4]; // this is OK
    }
}

Edited 6 Years Ago by ddanbe: n/a

Hi,

I'm so unskilled compared to you and I really shouldn't know things better than you :D but I think I know why, tell me please if I'm wrong!

TwoDShape[] shapes = new TwoDShape[4];

this will create the array only, but it will not instantiate the members in it, they'll be all nulls :D maybe you knew this before...

Comments
Thanks :)

Oops! You are quite right, I had the same issue once with an array of TextBoxes.:'(
Thank you for reminding me.:)
And, he, I'm only human, so lets consider this a slip of the mind on my behalf.
Thanks.

This question has already been answered. Start a new discussion instead.