Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

why cant instantiate an abstract class

Wed Oct 22, 2008 12:46 am

My question is why java has put the restriction that you can not
instantiate an abstract class, I know that abstract classes are meant to be
extended but we can think this way that lets say a class has three methods,
out of which one is abstract.

Now it would not be better that java allows to create the object of that
class so that we can use the functionality of the two non-abstract methods
and if some one tries to use an abstract method then run time exception or
any thing else could be done.

So why java chose to put restriction on instantiation of abstract class
??????



Re: why cant instantiate an abstract class

Wed Oct 22, 2008 12:47 am

Abstract classes not only choose not to implement specific methods, but
typically these abstract methods are used by the concrete methods. This
way a programmer can code the program flow in a concrete method while
leaving the details of how it works to a subclass.

For an example, take a look at the Collections framework. Sun provided
abstract base classes for most interfaces such as List and Map. These
classes can implement some methods fully, and some are abstract. Some of
the concrete methods in abstract classes call into abstract methods, and
such method calls would fail.

In any event, does it make any sense to instantiate an AbstractList? By
definition, it is not complete and cannot provide a full implementation
of the List interface.

Post a reply
  Related Posts  to : why cant instantiate an abstract class
 java abstract class,concrete class and interface     -  
 What is an Abstract Class? !!!     -  
 make abstract class     -  
 how to Define abstract class in php     -  
 The difference between an Interface and an Abstract class     -  
 What is an abstract method     -  
 Abstract Classes in jsp     -  
 Define class helper class to check the method existance     -  
 Button action listener should implement abstract method     -  
 relationship between the Canvas class and the Graphics class     -  

Topic Tags

Java OOP