When a class extends the Thread class ,it should override ............ method of Thread class to start that thread.
When a class extends the Thread class ,it should override ............ method of Thread class to start that thread.
Which of the following are methods of the Thread class?
1) yield()
2) sleep(long msec)
3) go()
4) stop()
Which of the following are methods of the Thread class?
1) yield()
2) sleep(long msec)
3) go()
4) stop()
What notifyAll() method do?
What notifyAll() method do?
Which keyword when applied on a method indicates that only one thread should execute the method at a time.
Which keyword when applied on a method indicates that only one thread should execute the method at a time.
What will happen when you attempt to compile and run the following code?
1. public class Test extends Thread{
2. public static void main(String argv[]){
3. Test t = new Test();
4. t.run();
5. t.start();
6. }
7. public void run(){
8. System.out.println("run-test");
9. }
10. }
What will happen when you attempt to compile and run the following code?
1. public class Test extends Thread{
2. public static void main(String argv[]){
3. Test t = new Test();
4. t.run();
5. t.start();
6. }
7. public void run(){
8. System.out.println("run-test");
9. }
10. }
In java a thread can be created by ..........
In java a thread can be created by ..........
What is the output for the below code ?
class A implements Runnable{
public void run(){
System.out.println(Thread.currentThread().getName());
}
}
1. public class Test{
2. public static void main(String... args){
3. A a = new A();
4. Thread t = new Thread(a);
5. t.setName("good");
6. t.start();
7. }
8. }
What is the output for the below code ?
class A implements Runnable{
public void run(){
System.out.println(Thread.currentThread().getName());
}
}
1. public class Test{
2. public static void main(String... args){
3. A a = new A();
4. Thread t = new Thread(a);
5. t.setName("good");
6. t.start();
7. }
8. }
Analyze the following code:
public abstract class Test implements Runnable{
public void doSomething() { };
}
Analyze the following code:
public abstract class Test implements Runnable{
public void doSomething() { };
}
What will happen after compiling and running following code?
class A implements Runnable{
public void run(){
System.out.println("run-a");
}
}
1. public class Test{
2. public static void main(String... args){
3. A a = new A();
4. Thread t = new Thread(a);
5. t.start();
6. t.start();
7. }
8. }
What will happen after compiling and running following code?
class A implements Runnable{
public void run(){
System.out.println("run-a");
}
}
1. public class Test{
2. public static void main(String... args){
3. A a = new A();
4. Thread t = new Thread(a);
5. t.start();
6. t.start();
7. }
8. }
What will be output of the following program code?
public class Test implements Runnable{
public void run(){
System.out.print("go");
}
public static void main(String arg[]) {
Thread t = new Thread(new Test());
t.run();
t.run();
t.start();
}
}
What will be output of the following program code?
public class Test implements Runnable{
public void run(){
System.out.print("go");
}
public static void main(String arg[]) {
Thread t = new Thread(new Test());
t.run();
t.run();
t.start();
}
}
What will happen when you attempt to compile and run the following code?
class A implements Runnable{
public void run(){
System.out.println("run-A");
}
}
1. public class Test{
2. public static void main(String argv[]){
3. A a = new A();
4. Thread t = new Thread(a);
5. System.out.println(t.isAlive());
6. t.start();
7. System.out.println(t.isAlive());
8. }
9. }
What will happen when you attempt to compile and run the following code?
class A implements Runnable{
public void run(){
System.out.println("run-A");
}
}
1. public class Test{
2. public static void main(String argv[]){
3. A a = new A();
4. Thread t = new Thread(a);
5. System.out.println(t.isAlive());
6. t.start();
7. System.out.println(t.isAlive());
8. }
9. }
What is the output for the below code ?
public class Test extends Thread{
public static void main(String argv[]){
Test t = new Test();
t.run();
}
public void start(){
for(int i = 0; i < 10; i++){
System.out.println("Value of i = " + i);
}
}
}
What is the output for the below code ?
public class Test extends Thread{
public static void main(String argv[]){
Test t = new Test();
t.run();
}
public void start(){
for(int i = 0; i < 10; i++){
System.out.println("Value of i = " + i);
}
}
}
What will be the output?
class One extends Thread{
public void run(){
for(int i=0; i<2; i++){
System.out.print(i);
}
}
}
public class Test{
public static void main(String args[]){
Test t = new Test();
t.call(new One());
}
public void call(One o){
o.start();
}
}
What will be the output?
class One extends Thread{
public void run(){
for(int i=0; i<2; i++){
System.out.print(i);
}
}
}
public class Test{
public static void main(String args[]){
Test t = new Test();
t.call(new One());
}
public void call(One o){
o.start();
}
}
What will be the output of the following program code?
public class Test implements Runnable{
public static void main(String[] args){
Thread t = new Thread(this);
t.start();
}
public void run(){
System.out.println("test");
}
}
What will be the output of the following program code?
public class Test implements Runnable{
public static void main(String[] args){
Thread t = new Thread(this);
t.start();
}
public void run(){
System.out.println("test");
}
}
What will be the output after compiling and executing the following code?
public class Test implements Runnable{
public static void main(String[] args) throws InterruptedException{
Thread a = new Thread(new Test());
a.start();
System.out.print("Begin");
a.join();
System.out.print("End");
}
public void run(){
System.out.print("Run");
}
}
What will be the output after compiling and executing the following code?
public class Test implements Runnable{
public static void main(String[] args) throws InterruptedException{
Thread a = new Thread(new Test());
a.start();
System.out.print("Begin");
a.join();
System.out.print("End");
}
public void run(){
System.out.print("Run");
}
}
What will be the output?
class A extends Thread{
public void run(){
for(int i=0; i<2; i++){
System.out.println(i);
}
}
}
public class Test{
public static void main(String argv[]){
Test t = new Test();
t.check(new A(){});
}
public void check(A a){
a.start();
}
}
What will be the output?
class A extends Thread{
public void run(){
for(int i=0; i<2; i++){
System.out.println(i);
}
}
}
public class Test{
public static void main(String argv[]){
Test t = new Test();
t.check(new A(){});
}
public void check(A a){
a.start();
}
}
Which of the following constructor of class Thread is valid one?
Which of the following constructor of class Thread is valid one?
Analyze the following code:
public class Test implements Runnable{
public static void main(String[] args){
Test t = new Test();
}
public Test(){
Thread t = new Thread(this);
t.start();
}
public void run(){
System.out.println("test");
}
}
Analyze the following code:
public class Test implements Runnable{
public static void main(String[] args){
Test t = new Test();
}
public Test(){
Thread t = new Thread(this);
t.start();
}
public void run(){
System.out.println("test");
}
}
Predict the output:
public class Test extends Thread{
private int i;
public void run(){
i++;
}
public static void main(String[] args){
Test a = new Test();
a.run();
System.out.print(a.i);
a.start();
System.out.print(a.i);
}
}
Predict the output:
public class Test extends Thread{
private int i;
public void run(){
i++;
}
public static void main(String[] args){
Test a = new Test();
a.run();
System.out.print(a.i);
a.start();
System.out.print(a.i);
}
}
Predict the output:
class A implements Runnable{
public void run(){
try{
for(int i=0;i<4;i++){
Thread.sleep(100);
System.out.println(Thread.currentThread().getName());
}
}catch(InterruptedException e){
}
}
}
public class Test{
public static void main(String argv[]) throws Exception{
A a = new A();
Thread t = new Thread(a, "A");
Thread t1 = new Thread(a, "B");
t.start();
t.join();
t1.start();
}
}
Predict the output:
class A implements Runnable{
public void run(){
try{
for(int i=0;i<4;i++){
Thread.sleep(100);
System.out.println(Thread.currentThread().getName());
}
}catch(InterruptedException e){
}
}
}
public class Test{
public static void main(String argv[]) throws Exception{
A a = new A();
Thread t = new Thread(a, "A");
Thread t1 = new Thread(a, "B");
t.start();
t.join();
t1.start();
}
}
Analyze the following code:
public class Test implements Runnable{
public static void main(String[] args){
Test t = new Test();
t.start();
}
public void run() { }
}
Analyze the following code:
public class Test implements Runnable{
public static void main(String[] args){
Test t = new Test();
t.start();
}
public void run() { }
}
Given the code. What will be the result?
public class Test implements Runnable{
public static void main(String[] args) throws InterruptedException{
Thread a = new Thread(new Test());
a.start();
System.out.print("Begin");
a.join();
System.out.print("End");
}
public void run(){
System.out.print("Run");
}
}
Given the code. What will be the result?
public class Test implements Runnable{
public static void main(String[] args) throws InterruptedException{
Thread a = new Thread(new Test());
a.start();
System.out.print("Begin");
a.join();
System.out.print("End");
}
public void run(){
System.out.print("Run");
}
}