Meaningless Drivel is fun!*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "final" Watch "final" New topic
Author

final

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
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.
Thanks!
Anonymous
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
Wanderer
Sheriff

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
Anonymous
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.
Regards
Tushar Kansara
------------------
Anonymous
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: http://aspose.com/file-tools
 
subject: final
 
Similar Threads
final class
final variable are class variables? is it right?
some ?s!
Local class
static vars in inner classes