• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Herland Cid
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20742
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Paul!
 
James X Peterson
Whizlabs Java Support
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic