File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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


kalyan v

Joined: Jun 27, 2001
Posts: 5
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.

So much trouble in the world -- Bob Marley
Jessica Sant

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

Joined: Dec 10, 2001
Posts: 7023
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]
I agree. Here's the link:
subject: final!
It's not a secret anymore!