• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Marcus Green Mock Exam 2

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 http://java.sun.com/products//jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc6.html
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.
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Marcus

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Why?
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It's a tiny ad. At least, that's what she said.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic