This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extendable, but not instantiatable

 
David Duran
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make a class extendable, but not instantiatable. Is that even possible?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare it abstract, or give it a private constructor.
hth,
bear
 
David Duran
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear.
I'll try the abstract idea, but the private constructor idea can't work. If a subclass extends a superclass, the superclass' constructorwill be called before the subclass'. If the superclass' constructor is private, it will through a compile-time error.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the key purposes of making a class abstract is to prevent it from being instantiated. Abstract classes do not have to have abstract methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic