Why we can't create the object of abstract class ?
Answers were Sorted based on User's Feedback
Answer / ian
The reason behind this is , the abstract class contains
abstract methods which cant do any job. Calling such
function is meaningless. So it is not allowed to
instantiate abstract class
Is This Answer Correct ? | 63 Yes | 35 No |
Answer / vijay
Hello all am vijay
I can say most of the above answers are partially correct
but not upto the mark.
The exact reason is .
The function address of the pure virtual function is not
put into VTABLE of the abstract class , hence VTABLE of the
abstract is incomplete.
So when the user tries to create an instance of the
abstract class the compliler will throw an error.
Is This Answer Correct ? | 32 Yes | 7 No |
Answer / abhishek ajmera
When we declare a pure virtual function like this:-
Virtual PureVirtualFunction()=0;
This indicates compiler to reserve a slot for Function in VTABLE but don’t put an address in that particular slot. If only one function in a class is declared as pure virtual, the VTABLE is incomplete.
If the VTABLE for a class is incomplete, compiler cannot safely create an object of a pure abstract class, so you get an error message from the compiler if you try to make an object of a pure abstract class. Thus, the compiler ensures the purity of the abstract class, and you don’t have to worry about misusing it.
Is This Answer Correct ? | 10 Yes | 1 No |
Answer / mallikharjun d
Hi frnds..the simple answer for this question is..
we cant create object for an abstract class bcz abstract class should be inherited to derived class, due to that reason we can access abstract members using derived class object..
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / talk
Because object means it will occupy memory and 'do something'
but what exactly it will do ?? it is not told in an abstract
class as because there is only abstract methods declared but
not defined. Therefore, there is not meaning to create an
object which does not have any definition.
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / rajesh kamble
abstract class contain one or more pure vertual
function ,this types of class contain only the declaration
of method ,it do not have defination of any method,when we
define any abstract class object it not allocate the memory
to any object , and when any object of class will created
it first initialise memory for class and then methods. and
look for the defination for that, for that point of view
when we create object of any abstract class method
defination will not present and memory cannot be allow to
object. any by the compiler it cause the error.
Is This Answer Correct ? | 8 Yes | 7 No |
Answer / santosh bind
Abstract Class Contain a method without or a body empty implemantation. so we can not create the object of abstract Class.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / uday eshkilla
simple answer is, we can't create the object of abstract class, because they contain only abstract members, any abstract class can not have implements it is basically incomplete…
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / srikanth
If we define a class with abstract keyword then the class
will be abstract class irrespective of abstract methods(un
inplemented methods)every one know that.
While compilation compiler checks whether the class is
abstract or not? if it's abstract it gives the compilation
error...
Is This Answer Correct ? | 2 Yes | 6 No |
Define assert() method? How does it work?
Why do we use dictionary in c#?
How do I unload an application domain?
What is strong name assembly?
How do you create dlls in .NET
What is binding in c#?
Does c# support #define for defining global constants?
Difference between call by value and call by reference in C#?
What are handlers in c#?
Why is lazy loading?
What is cshtml extension?
what is the difference between .dll and .exe