• Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract class  RSS feed

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can abstract classes have constructors ?

If yes when do they get invoked ?
Thanks,
Jose
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just try writing an abstract class with a constructor, and try out whether it compiles?
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out that we can have constructor in Abstract class, but what is the point ? Abstract classes cannot be instantiated, then whats the need for constructors?


Thanks.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Create a subclass to the abstract class. You will see that the abstract class constructor is called when the subclass is instantiated.

Henry
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[DELETED to avoid confusion]

new question here...

http://www.coderanch.com/t/483697/Java-General/java/Thread
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for posting it here. I have posted this as a new topic. Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!