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