• Post Reply Bookmark Topic Watch Topic
  • New Topic

Static  RSS feed

 
rahul sengupta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know about the below statement


I do not want to know about the function Random but would like to know if this is a static object.

Thank You all in advance
 
Cole Terry
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rahul sengupta wrote:

I do not want to know about the function Random but would like to know if this is a static object.



In fact, there is no "static object". static is just one of Java keywords that define attribute of a variable.
Static variable is something like global variable, which is available to all instances of a class in which it is declared.
 
Sagar Dabas
Ranch Hand
Posts: 47
C++ Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reference variable " select " is the static variable..... that means only one copy of " select " will be available for all the objects of the class in which it is declared.

There's not such thing like static object and if it was there, then static keyword has to used when defining the object's class not when object is instantiated. And that is also not possible since there's no point in having static classe (ofcourse, except inner classes).
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cole TerryStatic wrote:...[it] is something like global variable, which is available to all instances of a class in which it is declared.

It should perhaps also be pointed out that static variables are the exception rather than the rule, and you shouldn't rush to add the static keyword just for convenience of access.

In the case of java.util.Random, it makes sense, since it is a factory for creating random numbers and its methods are Thread-safe, so there's usually no point in creating a new Random object for each instance of your class (although you should read the caveat in the API documentation).

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!