This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Effects from using static class members from a final class, in another class 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 "Effects from using static class members from a final class, in another class" Watch "Effects from using static class members from a final class, in another class" New topic
Author

Effects from using static class members from a final class, in another class

Herland Cid
Greenhorn

Joined: Feb 28, 2013
Posts: 6
Hi. I am looking forward to use static class members from a final class, in a normal class. Is there a way this can be implemented directly?

Here is my attempt. I instantiate the static class member, I want to use it directly (following the principle that says, static class members will exist independently of any class instance).

Any lights on this, is there a close point that could equal my attempt? Here it is:



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

First of all it doesn't matter that the class is final. Using one of its static members has nothing to do with whether the class can be extended (which is what final is about).

And don't create an instance of the class for the purpose of accessing the static member. It's true that Java allows you to do that, but it's unnecessary and confusing, so don't do it that way. Just use the ordinary way where you use the class to access the member:

Herland Cid
Greenhorn

Joined: Feb 28, 2013
Posts: 6
Thank you Paul!
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi Herland ,

As Paul said you can use the static members directly by using class name.
If you declare any member (Either variable or method) as static then you can access that member using class name. But in your code you are trying to access the member by creating an object instead use class name it will save memory.

Regards,
James
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Effects from using static class members from a final class, in another class
 
Similar Threads
Using final as program-wide variables
Help with an iteration
Doubt In Static Memeber...Plz Help Me
static final int allowed in non-static inner class
public vs protected instance members