The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Static...this is how it works

Posted by Bumle on May 15, 2001 at 1:07 PM

When u declare a variable or method to be static, all objects in that class can use that variable or method. But if u want other classes to be able to use that variable or method as well, even if they are not in the same package, u have to declare it as beeing public. Then u have to import that class in the class where u have to use the static variable or method.
But the fine thing about static is that the variable becomes availeble for all objects in the class. So that u don't have to use the dot notation for every single objekt.variable every time u have to use that variable.
I hope this helps you


> can a static variable can be invoked by an object of that class
> eg. obj.staticvar;
>
> i tried out this and it is happening , i dont know why is this happening since the static variable does not belong to that class,then how come the static variables can be invoked by and object of that class?






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us