File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Is volatile is only for instance variable? (error on ExamLab test 3) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Is volatile is only for instance variable? (error on ExamLab test 3)" Watch "Is volatile is only for instance variable? (error on ExamLab test 3)" New topic
Author

Is volatile is only for instance variable? (error on ExamLab test 3)

Emanuele Ghe
Ranch Hand

Joined: Feb 04, 2009
Posts: 111
Hi,
on examlab test 3, reviewing my answers, I've read that volatile is a keyword applicable only to instance variables.

In fact, this is false, because if you try to compile a program with a static volatile variable, the program perfectly compile, and also in the javadoc there are sun examples of static volatile variables:

http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html

Can someone confirm this to me ?

Thanks.


SCJP6 with score 90%. I am conscious of my ignorance and ready to learn from everyone.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

I have moved this post to our Mock Exam Errata forum.
That forum is dedicated to "problems with mock exams everywhere".


OCUP UML fundamental and ITIL foundation
youtube channel
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Good point. The question should have been about member variables,
as compared to stack or local variables. And it's not just primitives.
Remember that a reference variable can be volatile too.

Jim ... ...


BEE MBA PMP SCJP-6
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3164
    
  47

Emanuele,

Thanks for the feedback, and sorry, I didn't see this post before
Can you please tell me the question number where you found this problem - if so, I can make it correct with the next release of ExamLab. For me, I couldn't find a statement like that in practice exam 3.

Thanks,

Devaka


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
M. White
Greenhorn

Joined: Dec 27, 2009
Posts: 18

same goes with volatile modifier, it compiles on a static member. As stated is K&B Study Guide 6 Page 72:
The transient modifier applies only to instance variables.
The volatile modifier applies only to instance variables.


As stated also in the url you given by Emanuele:

FieldModifiers:
FieldModifier
FieldModifiers FieldModifier

FieldModifier: one of
public protected private
static final transient volatile


Im not sure if this should be on a separate thread .

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is volatile is only for instance variable? (error on ExamLab test 3)