• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confusion  RSS feed

 
memati bas
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anyone explain the resaon of the following sentence ?

Note that you can also declare an entire class final � this prevents the class from being subclassed
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you write a class like this:



Then trying to do this:



will give you a compile error; because Foo is final, you aren't allowed to define a subclass of Foo.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The keyword "final" has slightly different meaning depending on what it's applied to.
  • A final variable cannot have its assignment changed.
  • A final method cannot be overridden.
  • A final class cannot be subclassed.
  •  
    memati bas
    Ranch Hand
    Posts: 85
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the replies...
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!