0

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 by ddanbe: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by CloneXpert
1

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...

Votes + Comments
Thanks :)
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.