• Courses
  • Tutorials
  • Practice
Switch to Dark Mode

Java Synchronization Basics

Here are 10 essential multiple-choice questions on Java Synchronization Basics, covering key concepts.

Last Updated : Apr 25, 2025
Discuss
Comments

Question 1

Why is synchronization used in Java multithreading?

  • A

    To improve CPU performance

  • B

    To allow multiple threads to execute at once

  • C

    To prevent data inconsistency and race conditions

  • D

    To increase thread priority

Question 2

Which keyword is used to synchronize a method in Java?

  • A

    lock

  • B

    sync

  • C

    synchronized

  • D

    atomic

Question 3

What is the output of the following code?

Java
public synchronized void print() {
    System.out.println("Start");
    try { Thread.sleep(100); } catch (Exception e) {}
    System.out.println("End");
}
  • A

    Will always print "Start" and "End" together

  • B

    Will print "Start" only

  • C

    Might throw InterruptedException

  • D

    Prints "End" before "Start"

Question 4

Which of the following can be synchronized in Java?

  • A

    Methods only

  • B

    Constructors

  • C

    Blocks and Methods

  • D

    Interfaces

Question 5

Which object does a synchronized instance method lock on?

  • A

    Class object

  • B

    The method itself

  • C

    The this object

  • D

    The parent class

Question 6

How do you synchronize a block of code inside a method?

  • A

    lock(this)

  • B

    synchronize(this)

  • C

    synchronized(this) { /* code */ }

  • D

    Thread.lock(this) {}

Question 7

Which type of lock is acquired when using a static synchronized method?

  • A

    Instance lock

  • B

    Local lock

  • C

    Class-level lock

  • D

    Method-level lock

Question 8

What is a potential problem with improper synchronization?

  • A

    Compilation error

  • B

    Memory leak

  • C

    Faster execution

  • D

    Deadlock

Question 9

Which interface or class in Java provides explicit locking besides synchronized?


  • A

    LockSupport

  • B

    ReentrantLock

  • C

    AtomicBoolean

  • D

    ThreadGroup

Question 10

What happens if two threads access a non-synchronized method of the same object?

  • A

    One thread waits

  • B

    Both can execute concurrently

  • C

    Compilation error

  • D

    JVM throws exception

There are 10 questions to complete.

Take a part in the ongoing discussion