Total members 11890 |It is currently Fri Apr 19, 2024 1:07 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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
??????




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

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.

_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
Have thanks: 0 time
Post new topic Reply to topic  [ 2 posts ] 

  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






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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