aspose file tools*
The moose likes Java in General and the fly likes final! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "final!" Watch "final!" New topic
Author

final!

kalyan v
Greenhorn

Joined: Jun 27, 2001
Posts: 5
Hi,
To make a java class non subclassable (final class), we can use final. But any other ways to make a class final.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
maybe making the class private too will work..
why do you need another way?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Only inner classes can be made private. Marking the class as final should suffice. The methods within the class will also be implicitly final.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

"kaylan v"
Welcome to the JavaRanch! Please adjust your displayed name to match the JavaRanch Naming Policy, particularly this section: "For your publicly displayed name, use a first name, a space, and a last name."
You can change it here.
Thanks! and again welcome to the JavaRanch!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
kalyan,
If you were to make the constructor(s) unavailable, the class would then be un-subclassable.
Instances of the class could still be obtained through some static method.
A class based on the singleton pattern, might choose to make it's contructor(s) private, and then control the any instance creation of the class through a static method (often named getInstance).


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: final!