It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Green Mock Exam 2 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 "Marcus Green Mock Exam 2" Watch "Marcus Green Mock Exam 2" New topic

Marcus Green Mock Exam 2

Alamu Vinai

Joined: Feb 01, 2001
Posts: 19
Which of the following statements about threading are true
1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a synchronized method of an object
4) Thread scheduling algorithms are platform dependent
Option 2,3,4 are given true. Regarding option 2, we can obtain mutually exclusive lock only on objects/class which has synchronized code, right? Can anyone explain this?
Another question:
Which of the following statements are true?
1) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.
2) Under no circumstances can a class be defined with the private modifier
3) A inner class may under some circumstances be defined with the protected modifier
4) An interface cannot be instantiated
3,4 are given true. Option 2 is not given true. A class can't be defined private, right? Why this option is not true?
[This message has been edited by Alamu Vinai (edited March 21, 2001).]
Slightly Uber

Joined: Mar 21, 2001
Posts: 7
I also was a little off on this question, and prolly still am. Best i can come up with is that any object that enters synchronized code can have a lock. That object itself doesn't have to have synchronized code in its source file - can be any regular object. It's the method that the object is passed to that should be synchronized to obtain the lock of the object. So i am guessing that all objects have monitor(lock or semaphore which ever you prefer). Please correct me if I am wrong.
And the second question I think would be that a private class would have no accessibility - thus the JVM would not be able to access it to compile or run it and no other class would be able to reference or subclass it, thus rendering it pretty useless. Also please correct me.
Bob Young
Ranch Hand

Joined: Dec 23, 2000
Posts: 65
In answer to the question of whether or not a class can be declared private. RHE p. 91 table 3.1 states that top-level classes cannot be private. This article
off Sun's site states that inner classes can be private or protected within their enclosing classes. I think that the question is tricky. Look closely at the wording of "no circumstances". An inner-class is a class.
As it happened, the block of answers also leads to the correct answer. If you happened to know that an inner class can be defined with protected (answer 3) then this helps to answer question 2. I'm glad you posted this, I at first blush thought a class could not be private.
Marcus Green
arch rival

Joined: Sep 14, 1999
Posts: 2813
I try to give fairly detailed answers to my questions, including hyperlinks between the questions and the answers. Thus in the case of the private modifier for a class question I have an answer that includes the statement.
"An inner class can be defined with the private modifier."
Could I make the answer any more clear? I intend eventually having hyperlinks to the sections of my tutorial that go into more detail, but there is so much software and so little time. I think the Threading question could do with more explanation in the answer.

SCWCD: Online Course, 50,000+ words and 200+ questions
ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
As I know, top-level class can not be private.
But the static inner class is a top-level class too, right?
And the static inner class CAN be private.
Tanveer Mehmood
Ranch Hand

Joined: Feb 23, 2001
Posts: 51
Your first question:
2) You can obtain a mutually exclusive lock on any object
This is true, you can obtain exclusive lock on any object through synchronized blocks.
synchronized(object) { }
Second question:
I don't agree, you can declare private classes and its a common practice in case of inner classes.
I agree. Here's the link:
subject: Marcus Green Mock Exam 2
It's not a secret anymore!