The moose likes Java in General and the fly likes Final  classes in Java  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  classes in Java  " Watch "Final  classes in Java  " New topic

Final classes in Java

swarupa patil
Ranch Hand

Joined: Feb 22, 2006
Posts: 62
why String Math System and some other classes are Final ?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
The are two different reasons at play here:

1. String being final is part of String's design as an immutable class.

2. System and Math are utility classes with only static methods. There are not meant to be instantiated (and that's why their constructors are private). To emphasize the fact they are not meant to be instantiated, they are marked as final, although the lack of an accessible constructor would have stopped you anyway.

There is no emoticon for what I am feeling!
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I've always thought it's a shame that Java does not allow you to declare a class "abstract final". Then you could avoid defining any constructor at all.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
But I think "abstract" has the strong connotation of "built for subclassing", so that's why the combination "final+abstract" is illegal.
I agree. Here's the link:
subject: Final classes in Java
It's not a secret anymore!