We can't create objects of an abstract class, but we can create a List or an array of them. What is the difference?
-
1A list or array is simply a place holder for a set of pointers, and you have NOT created instances of anything yet. When you say Create Object - you mean create an instance - which you cannot do with an abstract class. But you can create Lists or Arrays that point to them (and are EMPTY) - then you can move the pointers to 'real' instances of derived classes/objects – Grantly Dec 25 '15 at 19:33
-
2@Grantly why not make it an answer ;) – quadroid Dec 25 '15 at 19:36
-
Sorry I was a bit confused at the time :) Thanks I shall, but all others I think have it covered - and I'm sure it will get downvoted lol...Here it goes now ;) – Grantly Dec 25 '15 at 19:40
-
3What is the difference between fruit and the box, where you could put some fruits? They are totally different. You can't grow fruit - you can grow apples or peaches, etc. But nothing prevents you from buying another box for storing fruits. – Dennis Dec 25 '15 at 19:48
-
1You can also create a list of interfaces, while you cannot create an instance of an interface directly... ;) – MBender Dec 26 '15 at 10:15
8 Answers
A list or array is simply a place holder for a set of pointers, and you have NOT created instances of anything yet.
When you say Create Object - you mean create an instance - which you cannot do with an abstract class.
But you can create Lists or Arrays that point to them (and are EMPTY) - then you can move the pointers to 'real' instances of derived classes/objects

- 2,546
- 2
- 21
- 31
-
2"and you have NOT created instances of anything yet." -- except the list or the array; that itself is an instance of list or array. – James Dunn Dec 25 '15 at 19:56
-
@TJamesBoone you are totally correct, but I didn't want to confuse or complicate the issue. My answer is not very comprehensive - and lacks details that others provide - but I was hoping for an answer to match the brevity of the question – Grantly Dec 25 '15 at 20:02
Summary of Answer:
The List or the array itself is not an abstract class, even if the type it declares it will hold is an abstract class.
More Detailed Answer:
Even though you can't make an object of an abstract class (the word "of" is somewhat vague, but obviously you mean as a direct instantiation of that class), you can make an object that is an instance of an abstract class (because it's an instance of a concrete class that extends said abstract class).
Basically, given abstract class Abstraction
, and concrete class Concrete
that extends Abstraction
, List<Abstraction>
means you can but anything in it that is an instance of something that extends Abstraction
, e.g. an instance of Concrete
. Although arrays are a bit different in some ways from Lists, the same goes for them as well.
Example:
Given this class:
public abstract class Abstraction {
}
And this class:
public class Concrete : Abstraction {
}
You can't do this:
Abstraction a = new Abstraction();
But you CAN do this:
Abstraction a = new Concrete();
And then you can do this:
IList<Abstraction> list = new List();
list.add(a);

- 8,064
- 13
- 53
- 87
-
1You probably meant `public class Concrete : Abstraction`, Note the colon, `extends` is Java. – This company is turning evil. Dec 26 '15 at 12:38
-
1Oops, you're right. It's been a while since I've been in C#, been doing a lot of Java the last few years. – James Dunn Dec 29 '15 at 00:41
It is possible to declare and initialise a list where the type of the members is an abstract class because to create this object you do not need to actually instantiate the abstract class.
Logically, the list is only a container for pointers.
For example, you can define a list of an abstract class, but this list can be at the beginning empty.
You can also initialise the list with an initial size, but at the beginning it will not contain references to actual objects: the initialisation will only preallocate space for the pointers.
The objects added to the list have to be instances of a concrete class that extends the abstract class.

- 3,726
- 2
- 33
- 47
You can't create an instance of an abstract class for obvious reasons but surely creating an instance of the List<T>
class is allowed regardless that T is an abstract class.
Let the abstract class be called ClassAbstract
.
- When you try to do -
new ClassAbstract()
, you try to create an object of theClassAbstract
. - When you do -
new List<ClassAbstract>()
, you create an object of theList<T>
class.

- 1
- 1

- 13,888
- 8
- 60
- 75
I believe u are simply strongly typing what the objects inside the array will be
So when it comes time to put instantiated objects into the array. It has to be an object that was extended from the abstract class

- 463
- 2
- 5
There are no pink magic unicorns.
But you can still build a stable for pink magic unicorns, you just won't ever be able to put any in there, because there aren't any.
More realistic analogy: you cannot go to the pet store and buy "a mammal". That's far too abstract a thing.
But, you can build a stable for mammals. And then you can buy horses, cows, dogs, cats, elephants, giraffes, wolves, leopards, and lions and put them in there. Maybe even pink magic unicorns, if you can find any.
(How to build a stable that can at the same time accommodate mice and hump whales is left as an exercise to the reader.)

- 363,080
- 75
- 446
- 653
-
When I read the first line of your answer, I thought that I clicked some other question and was reading answers for that. Then I checked if I was on the correct question. And then I understood your point. :D – displayName Dec 26 '15 at 16:27
No, you can't create an array "of them", because you can't put the abstract types into the list. A list of an abstract type holds any derived instances of the abstract type.
Just means any derived type of the abstract type can be in the list

- 43,549
- 15
- 93
- 156
-
2I think that the user meant a list that is declared as a list with members of the abstract class. This is definitely possible. – Marco Altieri Dec 25 '15 at 19:36
-
1sure thats possible, but he put "of them" and you can't put in abstract instances of the object – Keith Nicholas Dec 25 '15 at 19:38