gs gs128 Java Multithreading - Implementing Runnable Interface for Threads - Quiz No.1
gs gs128 Java Quiz
This quiz belongs to book/course code gs gs128 Java of gs organization. We have 136 quizzes available related to the book/course Java. This quiz has a total of 8 multiple choice questions (MCQs) to prepare and belongs to topic Java Multithreading. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Question 1: Which of these method is used to implement Runnable interface?
stop()
run()
runThread()
stopThread()
Question 2: Which of these method is used to begin the execution of a thread?
run()
start()
runThread()
startThread()
Question 3: Which of these statement is incorrect?
A thread can be formed by implementing Runnable interface only
A thread can be formed by a class that extends Thread class
start() method is used to begin execution of the thread
run() method is used to begin execution of a thread before start() method in special cases
Question 4: What will be the output of the following Java code?
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(); } }
My Thread
Thread[My Thread,5,main]
Compilation Error
Runtime Error
Question 5: What will be the output of the following Java code?
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(); } }
My Thread
Thread[My Thread,5,main]
Compilation Error
Runtime Error
Question 6: What will be the output of the following Java code?
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(); } }
My Thread
Thread[My Thread,5,main]
Compilation Error
Runtime Error
Question 7: What will be the output of the following Java code?
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(); } }
Thread[New Thread,0,main]
Thread[New Thread,1,main]
Thread[New Thread,5,main]
Thread[New Thread,10,main]