• Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract class in java  RSS feed

 
Dikshant Agarwal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we can't create object of abstract class ,when we can create its constructor?
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating a constructor is allowed because it allows you to reuse that constructor from concrete sub classes by calling it using super(...). You can't create an object by invoking the constructor in the abstract class directly. You have to create a concrete subclass that defines its constructors and calls the super class constructor because constructors are not inherited
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What E Armitage said.

In addition I'd like to add one more point. An object is something that has a state and a completely defined behaviour. Abstract ( they are 'abstract' -- here I mean the english usage ) classes, by their nature, are not concrete; they may have undefined behaviour. As such, I think, it makes little sense to be able to construct a direct object ( and what would it mean to have one? an object that has partially defined or undefined behaviour? That, by the nature of an object, can't be an object) of an abstract class.

Edit : By direct object, I mean an object that could be constructed as follows,



 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you would want your fields to be in the superclass.Now you set a make in a Car class or a Van constructor. That is why you need the Vehicle constructor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!