Why can't we create object for an abstract class?

Showing Answers 1 - 31 of 31 Answers

An abstract class is a class which doesnt have an implementation for one or more methods. It means that the jvm doesnt have any direction of what to do in case if someone calls the method which is abstract. So if you are able to create an object for the abstract class and call any abstract method of it the jvm will not be able to decide what to do and hence it my be crashed. So to avoid this situation we are restricted to instantiate a abstract class. If you need a object for that abstract class create a concrete subclass and create an object for it and use it.

An abstract class can include concrete methods and fields. In fact, an abstract class does not need to include any abstract methods. The abstract modifier simply indicates that the class cannot be instantiated.

  Was this answer useful?  Yes

Amit Patil

  • Sep 19th, 2007
 

We cant create an object for object class as it is supposed to be used in inheritance heirarcy. Abstract class may contain abstract methods which the inheriting class should implement. The abstract class may not contain abstract methods but is defined abstract just to prevent instantiation

  Was this answer useful?  Yes

sampra

  • Feb 14th, 2008
 

beacuse abstract class has not complte body ie class status is not clear so we cant create object

  Was this answer useful?  Yes

luffykun

  • Aug 9th, 2009
 

To create objects we generally use new keyword mentioning indirectly the size to allocate the memory.
We do not know the size occupied by abstact methods so we cannot create object for abstract methods.

  Was this answer useful?  Yes

Abstract Class is an incomplete class, a class which acts as Prototype Model for actual classes.

Also, Abstract Class have one or more pure virtual functions, i.e. having No Body, no implementation and with NULL Function pointers.

Thus, while being instantiation of an object of such class, compiler is not able to set the reference for all of the member functions, hence...
Creation of an object of such class (Abstract Class) gives compiler error, and do not allow one to create it.

  Was this answer useful?  Yes

vijaya

  • Jul 16th, 2015
 

In Most of the situations abstract classes contains only abstract method, some times abstract classes contains non-abstract methods also but its not recommended to write non-abstract methods in abstract classes. The purpose of creating object for a class is, for calling the methods of that class (for doing some task) abstract methods not having any implementation means these methods cant able to do anything, so we cant perform any thing by calling that method strictly speaking its unnecessary to call abstract methods, that is why they restrict the object creation of abstract classes

  Was this answer useful?  Yes

ambarish upadhyay

  • Aug 7th, 2015
 

We cannot create object in abstract class because when we can compile the abstract class the compiler create them incomplete so in the abstract class we cannot create object

  Was this answer useful?  Yes

Naveen Kumar K R

  • Jan 17th, 2016
 

In this case JVM does not know how much memory it has to allocate for that abstract method, because abstract method does not have any implementation. So JVM will not be able to allocate memory for that abstract method

  Was this answer useful?  Yes

Rowan Siwakoti (NepWeb)

  • Jun 10th, 2016
 

We can create object of an abstract class indirectly by using anonymous inner class. Thank you :)

  Was this answer useful?  Yes

akansha

  • Feb 28th, 2018
 

As you say abstract class has no complete body that is why we cannot create object but if we completed this body after that we also cannot create object why?

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions