Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why can't we instantiate abstract class

 
pavan Kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we can instantiate Interface,but why can't we intantiate abstract class.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't instantiate an interface.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't instantiate an interface. Whatever you can do with an interface, you can do with an abstract class, too - such as using it as the base for an anonymous inner class. (Well, short of inheriting more than one of it, of course.)
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you could instantiate it it wouldn't be abstract...
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pavan,

Just few words... An abtract class is a normal one, but additionnaly the class' designer declare that nobody can instanciante it. Abstract classes are used to describe basic concepts of an OO hierarchy. This is mainly a convenient way to declare general services a classes hierarchy provide.

So it doesn't make sense to instanciate an abtract class, nor to try to modify a constant(basically a variable you state to be unmodifiable)

Best regards,
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Often an abstract class also has abstract methods (i.e. methods that are declared but have no body). It just wouldn't make sense to allow you to instantiate these since some of the functionality is missing.

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic