Why does declaring an int field count as volatile fail to make count++ thread-safe in Java?
Correct answer C. The increment is a separate read, change and write
Topic / 115 questions
Java MCQs test your knowledge of the Java programming language, including the JVM, data types, operators, control statements, arrays and object-oriented ideas. They help computer science students and IT job applicants, and every question shows its correct answer instantly so you can check concepts as you practise.
Correct answer C. The increment is a separate read, change and write
Correct answer D. An IllegalMonitorStateException is thrown
Correct answer D. The heap
Correct answer B. In a frame on the JVM stack of the thread
Correct answer B. StackOverflowError
Correct answer D. When no live thread can reach it through references
Correct answer A. Only that it suggests the JVM should try to reclaim memory
Correct answer A. Both are eligible for garbage collection
Correct answer D. Exactly one
Correct answer C. java.util.function
Correct answer B. It must be final or effectively final
Correct answer B. 20
Correct answer B. Nothing
Correct answer A. The second count throws an IllegalStateException
Correct answer A. record
Correct answer C. p.x()
Correct answer C. As the declared type of a field
Correct answer A. The classes allowed to directly extend it
Correct answer A. An additional instance field
Correct answer A. The intrinsic lock of the object it is called on
This topic covers core Java that interviewers and written tests often check. Questions ask which component provides the runtime environment for bytecode, which is the Java Virtual Machine, and which operator allocates memory to arrays, the new operator. You will also meet instance variables created with each object, jump statements such as break, continue and return, and exception handling with try, catch and finally. Operator precedence items, including how division and multiplication share equal precedence, also appear. These basics are useful for software house tests, computer lecturer posts and placement rounds.
Pakistan
India
Bangladesh
The JVM, or Java Virtual Machine, runs Java bytecode. The JRE, or Java Runtime Environment, contains the JVM plus the libraries needed to run Java programs. The JDK, or Java Development Kit, includes the JRE along with development tools such as the compiler javac, so it is needed to write and compile programs.
The new operator is used to allocate memory to an array in Java, for example int[] marks = new int[10];. It creates the array object on the heap and initialises numeric elements to zero. The same operator is used to create objects from classes.
Last reviewed October 2026