+ 3
What is the answer?
How many lines of output will this code produce? class B implements Runnable { public void run() { System.out.println("B"); } } class A extends Thread { public void run() { System.out.println("A"); Thread t = new Thread(new B()); t.start(); } public static void main(String[ ] args) { A object = new A(); object.start(); } }
18 Answers
+ 8
A
B
+ 3
Instances an object type A and you execute it to that object, and in turn A execute B. The output is:
1. A
2. B
+ 3
2
+ 2
Two lines first A then B
+ 1
Result :
A
B
+ 1
2 (A and B )
+ 1
How many lines of output will this code produce?
class B implements Runnable {
public void run() {
System.out.println("B");
}
}
class A extends Thread {
public void run() {
System.out.println("A");
Thread t = new Thread(new B());
t.start();
}
public static void main(String[ ] args) {
A object = new A();
object.start();
}
}
//output:- A
B
Answer :- 2
+ 1
2
0
A
B
0
Answer :
2
0
2
0
The answer is NOT! A and B!!!
The answer is : 2
0
Answer: 2
0
2
0
2
0
2