File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes The use of static and final. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "The use of static and final. " Watch "The use of static and final. " New topic
Author

The use of static and final.

Silver
Greenhorn

Joined: Jan 16, 2002
Posts: 4
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

Joined: Aug 07, 2001
Posts: 418
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

Joined: Dec 28, 2001
Posts: 26
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

Joined: Aug 07, 2001
Posts: 418
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
 
 
subject: The use of static and final.