Most asked top Interview Questions and Answers & Online Test
Education platform for interview prep, online tests, tutorials, and live practice

Build skills with focused learning paths, mock tests, and interview-ready content.

WithoutBook brings subject-wise interview questions, online practice tests, tutorials, and comparison guides into one responsive learning workspace.

Prepare Interview

Answers for OCJP / SCJP Online Test - Online Exam - Online Quiz - Mock Test

←Go Back to Online Practice Test
Question.

What is the output for the below code?

class A extends Thread {
    int count = 0;
    public void run() {
        System.out.println("run");
        synchronized (this) {
            for(int i =0; i < 50 ; i++) {
                count = count + i;
            }
            notify();
        }
    }
}

 

public class Test {
    public static void main(String argv[]) {
        A a = new A();
        a.start();
        synchronized (a) {
            System.out.println("waiting");
            try {
                a.wait();
            } catch(InterruptedException e) {
            }
            System.out.println(a.count);
        }

    }
}


Option 1.

waiting run 1225

Option 2.

waiting run 0

Option 3.

waiting run and count can be anything

Option 4.

Compilation fails


Answer. Option 1

Save For Revision

Bookmark this item, mark it difficult, or place it in a revision set.

Open My Learning Library
Please provide the reason below. The best provided reason will be displayed with your name (if you are logged in) on the website.
Enter Reason
Security Check
Solve this to continue: 8 + 8 = ?
 
Is it helpful? Yes No
Copyright © 2026, WithoutBook.