574). Which of the interface contains all the methods used for handling thread related operations in Java?
[A]Runnable interface
[B]Math interface
[C]System interface
[D]ThreadHandling interface
Show Answer
Correct Answer: Runnable interface
Notes:
Answer: a
Explanation: Runnable interface defines all the methods for handling thread operations in Java.
575). Which of these class is used to make a thread?
[A]String
[B]System
[C]Thread
[D]Runnable
Show Answer
Correct Answer: Thread
Notes:
Answer: c
Explanation: Thread class is used to make threads in java, Thread encapsulates a thread of execution. To create a new thread the program will either extend Thread or implement the Runnable interface.
576). Which of this interface is implemented by Thread class?
[A]Runnable
[B]Connections
[C]Set
[D]MapConnections
Show Answer
Correct Answer: Runnable
Notes:
Answer: a
Explanation: None.
577). Which of these methods of a Thread class is used to suspend a thread for a period of time?
[A]sleep()
[B]terminate()
[C]suspend()
[D] stop()
Show Answer
Correct Answer: sleep()
Notes:
Answer: a
Explanation: None.
578). What will be the output of the following Java program?
class newthread implements Runnable
{
Thread t1,t2;
newthread()
{
t1 = new Thread(this,"Thread_1");
t2 = new Thread(this,"Thread_2");
t1.start();
t2.start();
}
public void run()
{
t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
[A]true
[B]false
[C]truetrue
[D]falsefalse
Show Answer
Correct Answer: falsefalse
Notes:
Answer: d
Explanation: Threads t1 & t2 are created by class newthread that is implementing runnable interface, hence both the threads are provided their own run() method specifying the actions to be taken. When constructor of newthread class is called first the run() method of t1 executes than the run method of t2 printing 2 times “false” as both the threads are not equal one is having different priority than other, hence falsefalse is printed.
Output:$ javac multithreaded_programing.java
$ java multithreaded_programing
falsefalse
579). What will be the output of the following Java program?
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"New Thread");
t.start();
}
public void run()
{
t.setPriority(Thread.MAX_PRIORITY);
System.out.println(t);
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
[A]Thread[New Thread,0,main]
[B]Thread[New Thread,1,main]
[C]Thread[New Thread,5,main]
[D]Thread[New Thread,10,main]
Show Answer
Correct Answer: Thread[New Thread,10,main]
Notes:
Answer: d
Explanation: Thread t has been made with default priority value 5 but in run method the priority has been explicitly changed to MAX_PRIORITY of class thread, that is 10 by code ‘t.setPriority(Thread.MAX_PRIORITY);’ using the setPriority function of thread t.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[New Thread,10,main]
580). What will be the output of the following Java program?
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
[A]My Thread
[B]Thread[My Thread,5,main]
[C]Compilation Error
[D]Runtime Error
Show Answer
Correct Answer: Compilation Error
Notes:
Answer: c
Explanation: Thread t has been made by using Runnable interface, hence it is necessary to use inherited abstract method run() method to specify instructions to be implemented on the thread, since no run() method is used it gives a compilation error.
Output:
$ javac multithreaded_programing.java
The type newthread must implement the inherited abstract method Runnable.run()
581). What will be the output of the following Java program?
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
public void run()
{
System.out.println(t.getName());
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
[A] My Thread
[B]Thread[My Thread,5,main]
[C] Compilation Error
[D]Runtime Error
Show Answer
Correct Answer: My Thread
Notes:
Answer: a
Explanation: None.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
My Thread
582). What will be the output of the following Java program?
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
public void run()
{
System.out.println(t);
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
[A] My Thread
[B]Thread[My Thread,5,main]
[C]Compilation Error
[D]Runtime Error
Show Answer
Correct Answer: Thread[My Thread,5,main]
Notes:
Answer: b
Explanation: None.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[My Thread,5,main]