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
??????
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.
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.