• 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

The use of static and final.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In some mock questions, I found there are such codes as:
static Object o=new Object();
final Object o=new Object();
I wonder the effect of these two keywords in declaring Object reference.
Please help me. Thanks.
 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static member implies that it belongs to class and not to the object.
eq.

you can directly access a static memeber using a classname w/o creating an object of that class.
fianl variable means that its value once initialized cant be changed later.
it basically acts like a constant.
HIH
Rashmi
Note o register with a valid name.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rashmi Gunjotikar:
static member implies that it belongs to class and not to the object.
eq.

you can directly access a static memeber using a classname w/o creating an object of that class.
fianl variable means that its value once initialized cant be changed later.
it basically acts like a constant.
HIH
Rashmi
Note o register with a valid name.


dear rashmi,
the point is can u have static objects declared in java unlike static variables.
happy exploring,
suraj
 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the point is can u have static objects declared in java unlike static variables.
What do u mean by declared in java.
- If u mean declaring it at class level, then u can have a static var or object as a class member. There is no distinction between a static var or object ref. at class level . they both act as class memner
-If u mean declaring it inside a method, then u can't have a var or object ref as static loacal to a method.
HIH
U better frame ur question properly.
Regards,
Rashmi
-----Happy Ranching
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic