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

Mock Exam Q

Pooja K
Greenhorn

Joined: Oct 27, 2000
Posts: 7
Hi,
I] 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 method declared with the keyword synchronized
4) Thread scheduling algorithms are platform dependent
Ans is 2,3,4..is 3 correct , because the thread obtains a lock on an object not on a method??

Which of the following statements are true?
1) static methods do not have access to the implicit variable called this
2) a static method may not be overriden
3) a static method may not be overriden to be non-static
4) a static method may not be overloaded
Ans given are 1 & 3 ..isn�t 2 also right???
Thanks in advance,
pooja
Milind Mahajan
Ranch Hand

Joined: Oct 23, 2000
Posts: 77
Hi,
answer 3 is also correct because, if I am not wrong, when a thread is executing synchronized method of an object, other thereads are free to execute that object's non-synchronized methods. So the object, as such is not locked. We can put it this way : Threads acquire lock on an object for it's synchronized methods. ( Anybody please correct me if I am wrong ).
And yes you are right. Ans.2 of second question is correct. Static methods cannot be overridden. They are actually 'hidden'. They do not participate in dynamic binding.
Hope this helps.
Milind
Pooja K
Greenhorn

Joined: Oct 27, 2000
Posts: 7
Thanks Milind
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
To complete Milind's answer, when a class method is using the same name, return type, and parameters as a method in its superclass, though it is similar to overriding, it is called shadowing (as shadowing superclass fields).
Regards,
Beno�t
[This message has been edited by Beno�t d'Oncieu (edited October 28, 2000).]
Aru Ven
Ranch Hand

Joined: Sep 28, 2000
Posts: 199
Hi Guys,
Regarding the second question....
Which of the following statements are true?
1) static methods do not have access to the implicit variable called this
2) a static method may not be overriden
3) a static method may not be overriden to be non-static
4) a static method may not be overloaded
If 2 is "TRUE", then how is 3 "TRUE" , should'nt it be false...
I have read several discussions in the past...where a few say
STATIC METHODS CANT BE OVERRIDDEN....
then when u run this code below... why do we get a compilation error....? Doesnt this prove that
STATIC METHODS CAN BE OVERRIDDEN....
Can anyone explain more clearly ?
class A1{
static void show(){
System.out.println("Hello Friends.....");
}
}
class A2 extends A1{
private static void show(){
System.out.println("Hello Javaranchites.....");
}
public static void main(String args[]){
show() ;
}
}
C:\java\bin>javac A.java
A.java:8: The method void show() declared in class A2 cannot override the method of the same signature declared in class A1. The access modifier is made more restrictive.
private static void show(){
^
1 error
Thanks,
Aruna
Mary Anitha
Greenhorn

Joined: Oct 13, 2000
Posts: 23
Aruna,
In your code the error I think is only because you are making it more restrictive(ie private) but not because you are overriding a static method.
The rules that I learnt are that
A static method cannot be overridden as non-static.
A non static method cannot be overridden as static.

Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi all,
Static methods are inherited by their subclasses. You can't override a static method with an instance (non-static) method.
<pre>
class Super {
static void staticTest() {
}
}
class Sub extends Super {
void staticTest() {

// this causes a compile error
// overridden method is static

}
}

</pre>
You can declare a static method in the subclass with the same signature as the static method in the superclass but this is hiding (JLS §6.1.3).
<pre>
class Sub extends Super {
static void staticTest() {

// compiles with no errors
// hides staticTest() in Super which
// can no longer be accessed through
// a Sub reference

}
}

</pre>
Hope that helps.
------------------
Jane


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock Exam Q