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");
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
Thread t = new Thread(a);
System.out.println(t.isAlive());
t.start();
System.out.println(t.isAlive());
}
}
class A implements Runnable{
public void run(){
System.out.println("run-A");
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
Thread t = new Thread(a);
System.out.println(t.isAlive());
t.start();
System.out.println(t.isAlive());
}
}
A. false run-A true
B. false run-A false
C. true run-A true
D. Compilation fails due to an error on line 7
E. None of these
Answer: Option A
Solution(By Examveda Team)
Once the start() method is called, the thread is considered to be alive.
Join The Discussion
Comments ( 1 )
A. A lightweight process that runs independently within a program
B. A data structure to store variables
C. A type of loop
D. A synchronization mechanism
Which interface is used to create a thread in Java?
A. Processor
B. Executor
C. Threadable
D. Runnable
What is the main advantage of using multithreading in Java programs?
A. Reduced memory usage
B. Simplicity of code
C. Improved program performance by utilizing multiple CPUs or CPU cores
D. Elimination of exceptions
How can you create a new thread in Java by implementing the Runnable interface?
A. Create an object of the Thread class
B. Create a class that implements the Runnable interface and override the run() method
C. Use the start() method of the main thread
D. Create an object of the Thread class
This Question can have multiple Answers like Option A, Option B, false true run-A
or many more are there.