aspose file tools*
The moose likes Beginning Java and the fly likes Extendable, but not instantiatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Extendable, but not instantiatable" Watch "Extendable, but not instantiatable" New topic
Author

Extendable, but not instantiatable

David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
I want to make a class extendable, but not instantiatable. Is that even possible?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Declare it abstract, or give it a private constructor.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
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

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extendable, but not instantiatable
 
Similar Threads
Sub class name- qualify clause
Interfaces containing Nested Classes (revamp of innerclasses)
How to design OO systems...
Another generic array creation scenario
Interactive Charts