• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

private static final object

 
Greenhorn
Posts: 12
Java ME Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic