on 09-21-2006 8:08 AM
Hello ! i a begginner in java..kindly help me in solving these questions.
wat'll happen when u compile and run this 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++){
System.out.println("Value of i=" + i);
}
}
}
Options----
1. A compile time error indicating that no run method is defined for the Thread class
2.A run time error indicating that no run method is defined for the Thread class
3.Clean compile and at run time the values 0 to 9 are printed out
4. Clean compile but no output at runtime
Hi
The Answer is
4. Clean compile but no output at runtime
Kind regads
Mukesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
/*
Hai enclosed is the code for your query.
option 4 is correct.
*/
public class Bground10 extends Thread{
public static void main(String args[ ]){
Bground10 b =new Bground10();
//b.run();clean compilation no out put because run method cannot be
//called by start
b.start(); //prints Value of i is 0 to Value of i is 9
// as start method is called.
//System.out.println("Hai Hello");
}
public void start(){
for(int i=0;i<10;i++){
System.out.println("value of i="+i);
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Payal,
For getting some output for the program u have posted , do override the default run method. This method is from tyhe Thread class. It will give some out. For trial, u can put some SOP (System.out.println) statement in a loop and check it out.
Cheers!!!!
Sukant Rudra
Note: Helpful answer, plz donate some points generously.
hi,
I executed the 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++){
System.out.println("Value of i=" + i);
}
}
}
it complied and there was no output at runtime.
Regards,
Richa.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.