File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The use of static and final.

 
Silver
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Rashmi Tambe
Ranch Hand
Posts: 418
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Suraj Berwal
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic