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

Khalid Mock Exam thread

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Hi All
there are few questions from Khaalid Mock Exam
Since answers are not provided I would be thnakful if you give your views
Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work?
CODE BLOCK A:
Runnable r = new Runnable() {
public void run() {
Work.doIt();
}
};
Thread t = new Thread(r);
t.start();
CODE BLOCK B:
Thread t = new Thread() {
public void start() {
Work.doIt();
}
};
t.start();
CODE BLOCK C:
Runnable r = new Runnable() {
public void run() {
Work.doIt();
}
};
r.start();
CODE BLOCK D:
Thread t = new Thread(new Work());
t.start();
CODE BLOCK E:
Runnable t = new Runnable() {
public void run() {
Work.doIt();
}
};
t.run();
a.Code block A
b.Code block B
c.Code block C
d.Code block D
e.Code block E

Only b is correct according to me as we cannot instaniate an Interface
what fo you all say ?


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
jafarali
Ranch Hand

Joined: Jul 15, 2000
Posts: 37
A & B are correct!!!

[This message has been edited by jafarali (edited July 24, 2000).]
pollai mandala
Greenhorn

Joined: Jun 16, 2000
Posts: 17
Hi jafarali,
B is not correct.
coz' here, Thread Object is created but u are overriding the start() method.So if we call start() method it is executed just like other methods but it will not create a new thread.That original functionality is hidden by your new version of start() method.

C is incorrect coz' start() method is not defined and hence invoking that method is a compile time error.
D is also incorrect.
E is similar like case A.Thread object is not created here also.
according to me A is the only correct answer.
what do you all say?
regards


Regards,<BR>Bhavani
jayesh bindra
Greenhorn

Joined: Jun 18, 2000
Posts: 26
Hi Gaurav,
The correct answer according to me is choice A.
What caught my eye was the statement that you made...
...we cannot instantiate an Interface
This is completly true but I think your concepts aren't totaly clear. Consider the following statements in Code Block A

Please take note that we are not instantiating the interface Runnable and assigning it to t, instead we are assigning to t a reference to the object of the anonymous inner class that implements Runnable. This assignment is completly legal.
Hope this is of some help to you.
Please correct me if I am wrong.
Regards,
Jayesh.
[This message has been edited by jayesh bindra (edited July 24, 2000).]
Herbert Maosa
Ranch Hand

Joined: May 03, 2000
Posts: 289
Just to place my vote. A is the only correct answer. I think the explanation has already been given, unless you want more.....
Herbert.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Gaurav,
You posted the same question under "Khalid Mock Exam on Garbage Collection" http://www.javaranch.com/ubb/Forum24/HTML/002666.html
and I answered it!....
This got me so because I thought I answered in this thread and my post was not here!!!.
Look at my answers there( right thread, wrong title ).
Ajith
PS : Gaurav, you have two postings with the same title "Khalid Mock Exam on Garbage Collection.". Only the newer one talks about GC, the older one talks about threads. And then you have the same question repeated!.

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
 
 
subject: Khalid Mock Exam thread