Declaring a class "final"

S

slippymississippi

I read this in a Java book, is this a typo? Shouldn't it be object,
not class?
 
I

IchBin

I read this in a Java book, is this a typo? Shouldn't it be object,
not class?
Java Language Specification
Third Edition

8.1.1.2 final Classes
A class can be declared final if its definition is complete and no
subclasses are desired or required. A compile-time error occurs if the
name of a final class appears in the extends clause (§8.1.4) of another
class declaration; this implies that a final class cannot have any
subclasses. A compile-time error occurs if a class is declared both
final and abstract, because the implementation of such a class could
never be completed (§8.1.1.1).

Because a final class never has any subclasses, the methods of a final
class are never overridden (§8.4.8.1).

http://java.sun.com/docs/books/jls/third_edition/html/classes.html#54727
--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
S

slippymississippi

Doh... that's right. "final" is used to prevent others from extending
your class... I hate it when languages overload keywords like that.

Thanks very much for the reminder!
 
Z

zero

(e-mail address removed) wrote in @g49g2000cwa.googlegroups.com:
Doh... that's right. "final" is used to prevent others from extending
your class... I hate it when languages overload keywords like that.

Thanks very much for the reminder!

seems to make perfect sense to me. final means that the
variable/reference/object/class cannot be changed after it's been created.
Changing an object is done by changing its values, changing a class by
extending it and overriding its methods. So, final does the same for both.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top