File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes final Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "final" Watch "final" New topic


Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
A final class makes its variables and methods as final
as well, since a final class cannot be extended.
Is the above statement true??
I think the above statement is true for final class methods.
But not for variables.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
1. final class - can not be extended.
2. final method - can not be overridden.
3. final variable - value can not be changed.
They are three different things, independent of each other except for the following.
A final class does not have to declare a method as final method, since the class can not be extended there is no question of overriding. If it declares, it is perfectly legal.
[This message has been edited by vasansrini (edited August 15, 2000).]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
avn- right. The methods of a final class are implicitly final, but not the fields.

"I'm not back." - Bill Harding, Twister
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

I think the above statement is true for final class methods.

I was confused about this statement. Why only "class methods", why not final instance methods ?
or we dont have anything called class methods. I thought class methods are nothing but static methods.
Jim ,
Help me.
Tushar Kansara
Ranch Hand

Joined: Aug 14, 2000
Posts: 38
The process of declaring a clas Final would no doubt dis allow any of its, class methods(Read Static)& Instance methods not to be overridden. But I am not sure about, The variables.
Say I have an static variable in a class declared final, can it be changed, when i am using an instance of the class & try to change the value in the variable. What about instance variables that have declared within the final class.
Tushar Kansara
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The value of the static and instance variables (which are not final) in a final class can be changed.They perform just
like variables in a class.
U cant override only the methods of the final class.
Deepak M
Ranch Hand

Joined: Jul 10, 2000
Posts: 124
"A method can be declared final to prevent subclasses from overriding or hiding it."
Static methods are hidden. !!
Instance methods are over-ridden. !!
It is a compile-time error to attempt to override or hide a final method.
A private method and all methods declared in a final class are implicitly final, because it is impossible to override or hide them.
It is permitted but not required for the declarations of such methods to redundantly include the final keyword.

I agree. Here's the link:
subject: final
Similar Threads
Local class
final class
final variable are class variables? is it right?
some ?s!
static vars in inner classes