File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

private static final object

 
Farid Abdi
Greenhorn
Posts: 12
Java Java ME Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am learning Java . In the book that I am reading is said about private and static fields and methods . But in a example code I saw a stange code :

private static final Random randomNumbers = new Random();

randomNumbers is an object of class Random

I am confused . Are there private and static objects ?? and if there are , What they mean ?? What is the meaning of a private or static object ??
I know the meaning of private or static fields and methods but I don't know the meaning of private and static objects .
Please help me...Thanks
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no difference. In that example randomNumbers is a private static field. So if you understand private and static fields you already understand it. In this case, the field holds a reference to a Random object, but if it held an int or a reference to a String the principle would be the same.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects do not have the property of being public or private, or static or non-static, final or non-final. Those concepts simply don't apply to objects. What you're seeing is a private static final variable.

private method: Cannot be accessed outside the class (or possibly "compilation unit"--have to check the JLS) where it's declared.
private variable: Cannot be accessed outside the class (or possibly "compilation unit"--have to check the JLS) where it's declared.

static method: Associated with the class as a whole, not with any particular instance. No "this" during execution.
static variable: Associated with the class as a whole, not with any particular instance. No associated "this".

final method: Cannot be overridden.
final variable: Cannot have its value changed after initialization.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic