Search code examples
language-agnosticoop

Why can't an object of abstract class be created?


Here is a scenario in my mind and I have googled, Binged it a lot but got the answer like

"Abstract class has not implemented method so, we cant create the object" "The word 'Abstract' instruct the compiler to not create an object of the class"

But in a simple class where we have all virtual method, able to create an object???

Also, we can define different access modified to Abstract class constructor like private, protected or public.

My search terminated to this question:

Why we can't create object of an Abstract class?


Solution

  • An abstract type is defined largely as one that can't be created. You can create subtypes of it, but not of that type itself. The CLI will not let you do this.

    An abstract class has a protected constructor (by default) allowing derived types to initialize it.

    For example, the base-type Stream is abstract. Without a derived type where would the data go? What would happen when you call an abstract method? There would be no actual implementation of the method to invoke.