aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q on Dan's Mock Exam(Synchronized) 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 "Q on Dan Watch "Q on Dan New topic
Author

Q on Dan's Mock Exam(Synchronized)

Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443

Which of the following modifiers can be applied to a field?
a. abstract
b. final
c. private
d. protected
e. public
f. static
g. synchronized
h. transient
i. volatile
j. native
k. strictfp
l. None of the above.

g. synchronized is NOT one of the answers.
But don't you consider the synchronized blocks as a form of applying the synchronized to a field?

From the code above, isn't it that we are applying the synchronized modifier to the field b?
Alexan Kahkejian
Ranch Hand

Joined: Apr 30, 2003
Posts: 74
Hi Alton
synchronized can only apply for methods or code blocks but never can be applied for variables.
Regarding your example you are synchronizing the block of code on the variable b.So no more than one thread can access b at the same time inside this block only, but outside the block b still can be accessed from more than one thread.So you are synchronizing the block but not the var b.
Hope that helps
Alexan
[ June 16, 2003: Message edited by: Alexan Kahkejian ]

Alexan Kahkejian<br />SCJP<br />SCWCD<br /><a href="http://www.javaemployer.com" target="_blank" rel="nofollow">http://www.javaemployer.com</a>
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
Hi Alexan,
Thank you for your explanation.
However, the issue here is the phrase applied to a field in the question. As I see it, a synchronized block is applying the modifier synchronized to both field and code block.
[ June 16, 2003: Message edited by: Alton Hernandez ]
Alexan Kahkejian
Ranch Hand

Joined: Apr 30, 2003
Posts: 74
Hi Alton
If you refer to JLS 8.3 you will notice that Fields are member variables, so the rule that I've mentioned apply.
Alexan
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Alton,
How do you feel about this new version of the question?

Which of the following modifiers can be applied to
the declaration of a field?


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
synchronized (Expression) Block
Maybe in this context, synchronized would not be called a modifier.
[ June 17, 2003: Message edited by: Marlene Miller ]
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
Originally posted by Marlene Miller:
synchronized (Expression) Block
Maybe in this context, synchronized would not be called a modifier.

I still consider it as a modifier because it is changing the behaviour of the block in relation to the object pointed to by the variable.
------
Originally posted by Dan Chisholm:
How do you feel about this new version of the question?
Which of the following modifiers can be applied to the declaration of a field?

This sounds about right to me.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Alton Hernandez:
I still consider it as a modifier because it is changing the behaviour of the block in relation to the object pointed to by the variable.
You may consider it a modifier but Java doesn't. "Modifier" has a very specific meaning in Java as defined by the JLS.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Originally posted by Alexan Kahkejian:
Hi Alton
If you refer to JLS 8.3 you will notice that Fields are member variables
Alexan

This means Fields reffer to methods & instance variables right?
Veena


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
This means Fields reffer to methods & instance variables right?

A class has members. Members can by classified as:
1. Member data:
This include constant (final variable) or variables. Their values could be primitive literals, objects or arrays. Member data are also know as fields.
2. Member method:
3. Member class:
So the answer is No. Fields do not refer to methods.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Q on Dan's Mock Exam(Synchronized)