File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Marcus Green Mock # 2  Ques. 18, 33, 51 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Marcus Green Mock # 2  Ques. 18, 33, 51" Watch "Marcus Green Mock # 2  Ques. 18, 33, 51" New topic
Author

Marcus Green Mock # 2 Ques. 18, 33, 51

Tejas Nakawala
Ranch Hand

Joined: Jan 04, 2001
Posts: 80
Hello all Java Lovers..
Pls clear my difficulties in folloing problems.
Help me pls....
Explain following ..Questions from Marcus Green Mock # 2.
Question 18)
What will happen when you attempt to compile and run the following code?
public class Bground extends Thread{
public static void main(String argv[]){
Bground b = new Bground();
b.run();
}
public void start(){
for (int i = 0; i <10; i++){<br /> System.out.println("Value of i = " + i);<br /> }<br /> }<br /> }<br /> 1) A compile time error indicating that no run method is defined for the Thread class<br /> 2) A run time error indicating that no run method is defined for the Thread class<br /> 3) Clean compile and at run time the values 0 to 9 are printed out<br /> 4) Clean compile but no output at runtime<br /> Ans => 4

Question 33)
What will happen when you attempt to compile and run this code
//Demonstration of event handling
import java.awt.event.*;
import java.awt.*;
public class MyWc extends Frame implements WindowListener{
public static void main(String argv[]){
MyWc mwc = new MyWc();
}
public void windowClosing(WindowEvent we){
System.exit(0);
}//End of windowClosing
public void MyWc(){
setSize(300,300);
setVisible(true);
}
}//End of class
1) Error at compile time
2) Visible Frame created that that can be closed
3) Compilation but no output at run time
4) Error at compile time because of comment before import statements
Ans => 1

Question 51)
Given the following code what will be the output?
class ValHold{
public int i = 10;
}
public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}//End of amethod
public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ " "+i);
}//End of another
}
1) 10,0, 30
2) 20,0,30
3) 20,99,30
4) 10,0,20
Ans => 4

Pls Dear Friend explain me the following problems.
Thank you very much

Tejas Nakawala
simenwu
Greenhorn

Joined: Feb 16, 2001
Posts: 2
Q)18.
A) Bground extends Thread, so it inherits the run() method.
Because it's an empty method, when you call b.run(), it outputs
nothing.
Q)33.
A)MyWc implements WindowListener, so it should implements all the
interface methods of WindowListener. And there are 6 other
methods beside the windowClosing.
Q) 51.
A) We can modify the object, but we can't change the reference passing into the method.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Simenwu,
Would you please read the JavaRanch Name Policy and re-register using a name that complies with the rules.
Your cooperation is appreciated.
Thanks.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Jan Volkmann
Greenhorn

Joined: Feb 01, 2001
Posts: 17
Originally posted by simenwu:
Q)18.
A) Bground extends Thread, so it inherits the run() method.
Because it's an empty method, when you call b.run(), it outputs
nothing.

I think M. Green explained it himself. It should've be:
b.start()
public void run
Kevin Cary
Ranch Hand

Joined: Jan 24, 2001
Posts: 53
Regarding question 18, Jan is correct. Marcus does give the answer to this question. In terms of explanation, b.start() must be called first to make a thread available. Another way to look at this code is:
public class Bground implements Runnable{
public static void main(String argv[]){
Bground b = new Bground();
//b.start();
b.run();
}
public void run(){
for (int i = 0; i <10; i++){
System.out.println("Value of i = " + i);
}
}
}
Here b.start() is not req because of the interface Runnable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marcus Green Mock # 2 Ques. 18, 33, 51