This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 2476
    
    7

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: 2885
    
  13

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
My Home Page -- Twitter Profile -- JavaRanch FAQ -- 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 .

 
 
subject: Is volatile is only for instance variable? (error on ExamLab test 3)
 
Similar Threads
Overridding Pls Explain this code
simple question
transient volatile strictfp 's position in SCJP1.4!
B&K book, error on page 80?
transient and volatile variables