Java Multiple Choice Question MCQ
Categories: Java
What is output for below
Collections.sort(list);
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
a) 1 2 5 8
b) 2 1 8 5
c) 1 5 8 2
d) 2 8 5 1
Answer: a
Ques 8. Which of these statements is incorrect about Thread?
a) start() method is used to begin execution of the thread
b) run() method is used to begin execution of a thread before start() method in special cases
c) A thread can be formed by implementing Runnable interface only
d) A thread can be formed by a class that extends Thread class
Answer: b
Ques 9. Which of these keywords are used for the block to be examined for exceptions?
a) check
b) throw
c) catch
d) try
Answer: d
Ques 10. What will be the output of the following Java code?
class newthread extends Thread
{
Thread t;
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) truetrue
b) falsefalse
c) true
d) false
Answer: b