Explore topic-wise MCQs in Java Programming.

This section includes 21 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?
class newthread implements Runnable 
{
Thread thread;
newthread()
{
thread = new Thread(this,"New Thread created...");
thread.start();
}
public void run()
{
System.out.println(thread);
}
}
public class multithreaded_Example
{
public static void main(String args[])
{
new newthread();
}
}

A. [New Thread created...,5,main]
B. New Thread created...
C. main
D. Thread[New Thread created...,5,main]
E. None of these
Answer» E. None of these
2.

What is the output of this program?
class newthread implements Runnable 
{
Thread thread;
newthread()
{
thread = new Thread(this,"My Thread created...");
thread.start();
}
public void run()
{
System.out.println(thread.getName());
}
}
public class multithreaded_Example
{
public static void main(String args[])
{
new newthread();
}
}

A. My Thread created...
B. My Thread
C. Thread created...
D. New Thread
E. None of these
Answer» B. My Thread
3.

What is the output of this program?
class newthread implements Runnable 
{
Thread thread;
newthread()
{
thread = new Thread(this,"My Thread");
thread.start();
}
}
public class multithreaded_Example
{
public static void main(String args[])
{
new newthread();
}
}

A. Runtime Error
B. Compilation Error
C. Thread[My Thread,5,main].
D. My Thread
E. None of these
Answer» C. Thread[My Thread,5,main].
4.

What is the output of this program?
class Mythread extends Thread 
{
Mythread()
{
super("New Thread...");
start();
}
public void run()
{
System.out.println(this);
}
}

public class multithreaded_programing
{
public static void main(String args[])
{
new Mythread();
}
}

A. New Thread...
B. [New Thread...,5,main]
C. Thread[New Thread...,5,main]
D. Thread
E. None of these
Answer» D. Thread
5.

What is the output of the thread in output of this program?
public class Output
{
public static void main(String args[])
{
Thread thread = Thread.currentThread();
System.out.println(thread.isAlive());
}
}

A. True
B. 0
C. 1
D. False
E. None of these
Answer» B. 0
6.

What is the name of the thread in output of this program?
public class multithreading_NameExample
{
public static void main(String args[])
{
Thread thread = Thread.currentThread();
thread.setName("Thread One");
System.out.println(thread.getName());
}
}

A. main
B. Thread one
C. Thread
D. Name
E. None of these
Answer» C. Thread
7.

What is the priority of the thread in output of this program?
public class multithreaded_PriorityExample
{
public static void main(String args[])
{
Thread thread = Thread.currentThread();
thread.setName("Thread One");
System.out.println(thread.getPriority());
}
}

A. 2
B. 1
C. 0
D. 5
E. 10
Answer» E. 10
8.

What is the output of this program?
public class multithreading_Example
{
public static void main(String args[])
{
Thread thread = Thread.currentThread();
thread.setName("Thread one");
System.out.println(thread);
}
}

A. Thread
B. Thread one
C. main
D. Thread[Thread one,5,main]
E. None of these
Answer» E. None of these
9.

What is the name of the thread in output of this program?
public class multithreaded_Name
{
public static void main(String args[])
{
Thread thread = Thread.currentThread();
thread.setName("First");
System.out.println(thread);
}
}

A. First
B. main
C. Thread
D. All of above
E. None of these
Answer» B. main
10.

What is the priority of the thread in output of this program?
public class multithreading_Priority 
{
public static void main(String args[])
{
Thread thread = Thread.currentThread();
System.out.println(thread);
}
}

A. 0
B. 1
C. 2
D. 4
E. 5
Answer» F.
11.

What is the output of this program?
public class multithreading_SimpleExample
{
public static void main(String args[])
{
Thread thread = Thread.currentThread();
System.out.println(thread);
}
}

A. Thread
B. Main
C. 5
D. Thread[main,5,main]
E. None of these
Answer» E. None of these
12.

What is the output of this program?
class N extends Thread
{
Thread thread;
String Str;
N(String ThreadName)
{
Str = ThreadName;
thread = new Thread(this,Str);
thread.start();
}
public void run()
{
}

}

public class multithreading_Example
{
public static void main(String args[])
{
N object1 = new N("First");
N object2 = new N("Second");
try
{
object1.thread.wait();
System.out.print(object1.thread.isAlive());
}
catch(Exception e)
{
System.out.print("Running Main Thread...");
}
}
}

A. First
B. Second
C. Running Main Thread...
D. All of above
E. None of these
Answer» D. All of above
13.

What is the output of this program?
class newthread implements Runnable 
{
Thread thread;
newthread()
{
thread = new Thread(this,"New Thread created...");
thread.start();
}
public void run()
{
thread.setPriority(Thread.MAX_PRIORITY);
System.out.println(thread);
}
}
public class multithreaded_Example
{
public static void main(String args[])
{
new newthread();
}
}

A. Thread[New Thread created...,10,main]
B. [New Thread created...,10,main]
C. New Thread created...
D. [New Thread created...,10,main]Thread
E. None of these
Answer» B. [New Thread created...,10,main]
14.

What is the output of this program?
class Mythread extends Thread 
{
Thread thread;
Mythread()
{
thread = new Thread(this,"New Thread");
thread.start();
}
public void run()
{
try
{
thread.join();
System.out.println(thread.getName());
}
catch(Exception e)
{
System.out.print("Exception");
}
}
}

public class multithreaded_programing
{
public static void main(String args[])
{
new Mythread();
}
}

A. New Thread
B. Thread
C. My Thread
D. Compilation Error
E. Runtime Error
Answer» F.
15.

What is the output of this program?
class n extends Thread
{
Thread thread;
n()
{
thread = new Thread(this,"New Thread");
thread.start();
}
public void run()
{
System.out.println(thread.isAlive());
}
}

public class multithreading_Example
{
public static void main(String args[])
{
new n();
}
}

A. Compilation Error
B. True
C. Runtime Error
D. False
E. None of these
Answer» C. Runtime Error
16.

What is the output of this program?
class N extends Thread
{
Thread thread;
String Str;
N(String ThreadName)
{
Str = ThreadName;
thread = new Thread(this,Str);
thread.start();
}
public void run()
{
}

}

public class multithreading_EqualsExample
{
public static void main(String args[])
{
N object1 = new N("Hello");
N object2 = new N("Java");
try
{
System.out.print(object1.thread.equals(object2.thread));
}
catch(Exception e)
{
System.out.print("Running main thread...");
}
}
}

A. Main Thread Running...
B. First
C. Second
D. True
E. False
Answer» F.
17.

What is the output of the thread in output of this program?

A. True
B. 0
C. 1
D. False
E. None of these
Answer» B. 0
18.

What is the name of the thread in output of this program?

A. First
B. main
C. Thread
D. All of above
E. None of these
Answer» B. main
19.

What is the priority of the thread in output of this program?

A. 0
B. 1
C. 2
D. 4
E. 5
Answer» F.
20.

Which of this method is used to find out that a thread is still running or not?

A. checkRun()
B. run()
C. Alive()
D. isAlive()
E. None of these
Answer» E. None of these
21.

Which of this method can be used to make the main thread to be executed last among all the threads?

A. call()
B. join()
C. stop()
D. sleep()
E. None of these
Answer» E. None of these