iGET

Java Programming - MCQ Practice Questions

Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.

951 questions | 100% Free

Q.161Medium

In the context of synchronized methods, what is acquired and released automatically?

Q.162Medium

What is the main advantage of using ExecutorService over directly creating threads?

Q.163Medium

In a multithreaded application, what does the term 'context switching' refer to?

Q.164Medium

In Java 21 (latest), which is a modern approach to create thread-safe operations?

Q.165Medium

What will be the output of the following code?

Object lock = new Object();
synchronized(lock) {
synchronized(lock) {
System.out.println("Nested");
}
}

Q.166Medium

Which interface would you use to submit multiple tasks and wait for all of them to complete?

Q.167Medium

What is the difference between notify() and notifyAll() in Java?

Q.168Medium

Which of the following best describes CyclicBarrier?

Q.169Medium

What happens when a thread acquires a lock on an object and then calls wait()?

Q.170Medium

In a scenario where Thread A holds Lock1 and waits for Lock2, while Thread B holds Lock2 and waits for Lock1, what is this called?

Q.171Medium

What is the output of this code?

ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> System.out.println("Task 1"));
executor.submit(() -> System.out.println("Task 2"));
executor.shutdown();

Q.172Medium

Which method is used to forcefully stop a thread in modern Java?

Q.173Medium

What happens if an exception is thrown inside a synchronized block?

Q.174Medium

In Java 21 Virtual Threads, what is the key advantage over platform threads?

Q.175Medium

What does the volatile keyword guarantee in Java multithreading?

Q.176Medium

What is the output of the following code?
volatile int counter = 0;
counter++; // in multiple threads
Which issue may occur?

Q.177Medium

What is CyclicBarrier used for in multithreading?

Q.178Medium

Which of the following is true about CountDownLatch?

Q.179Medium

What is the purpose of the wait() method in Java?

Q.180Medium

In a synchronized block, if notifyAll() is called, what happens?