Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 871–880 of 958 questions
Q.871 Easy Basics & Syntax
Which of the following statements about Java's garbage collection is TRUE?
A Garbage collection is guaranteed to run at specific time intervals
B The programmer must explicitly call System.gc() to free memory
C Garbage collection automatically reclaims memory used by unreferenced objects
D Java does not have automatic garbage collection mechanism
Correct Answer:  C. Garbage collection automatically reclaims memory used by unreferenced objects
EXPLANATION

Java's garbage collector automatically identifies and reclaims memory of objects that are no longer referenced. While System.gc() can be suggested, it's not guaranteed to execute immediately.

Take Test
Q.872 Easy Basics & Syntax
Consider the following code snippet. What is the primary purpose of the 'final' keyword when applied to a class in Java?
A Prevents the class from being instantiated
B Prevents the class from being inherited by other classes
C Makes all methods in the class abstract
D Allows the class to be accessed globally without import
Correct Answer:  B. Prevents the class from being inherited by other classes
EXPLANATION

The 'final' keyword when applied to a class prevents it from being extended or inherited. This is a fundamental OOP concept in Java used to restrict inheritance.

Take Test
Q.873 Easy Basics & Syntax
What is the output of: System.out.println(5 > 3 ? "Yes" : "No");?
A 5
B 3
C Yes
D No
Correct Answer:  C. Yes
EXPLANATION

This uses the ternary operator (conditional operator). The condition 5 > 3 is true, so it returns the value after the '?', which is "Yes".

Take Test
Q.874 Easy Basics & Syntax
Which of the following is NOT a Java keyword?
A synchronized
B volatile
C thread
D transient
Correct Answer:  C. thread
EXPLANATION

'thread' is not a Java keyword. 'synchronized', 'volatile', and 'transient' are all valid Java keywords used for special purposes.

Take Test
Q.875 Hard Basics & Syntax
What will happen in this code: int x = Integer.MAX_VALUE; x++;?
A x becomes a very large number
B x overflows and becomes Integer.MIN_VALUE
C Throws an exception
D Compilation error
Correct Answer:  B. x overflows and becomes Integer.MIN_VALUE
EXPLANATION

In Java, integer overflow wraps around. When an int exceeds Integer.MAX_VALUE (2147483647), it overflows and wraps to Integer.MIN_VALUE (-2147483648).

Take Test
Q.876 Medium Basics & Syntax
Which method is called automatically when an object is garbage collected?
A finalize()
B destroy()
C delete()
D cleanup()
Correct Answer:  A. finalize()
EXPLANATION

The finalize() method is called by the garbage collector before an object is destroyed. It can be used to perform cleanup operations, though it's generally not recommended in modern Java.

Take Test
Q.877 Hard Basics & Syntax
What is the result of: System.out.println('A' + 'B');?
A AB
B 131
C Compilation error
D 131.0
Correct Answer:  B. 131
EXPLANATION

Characters are promoted to their integer ASCII values in arithmetic operations. 'A' has ASCII value 65 and 'B' has ASCII value 66, so 65 + 66 = 131.

Take Test
Q.878 Medium Basics & Syntax
Which of the following will compile and run without errors?
A public static void main() { }
B public static void main(String[] args) { }
C public void main(String[] args) { }
D static void main(String[] args) { }
Correct Answer:  B. public static void main(String[] args) { }
EXPLANATION

The correct signature for the main method is 'public static void main(String[] args)'. It must be public, static, void, named 'main', and accept a String array parameter. Any deviation will not be recognized as the entry point.

Take Test
Q.879 Medium Basics & Syntax
Which of the following correctly represents variable declaration and initialization in Java?
A int x; x = 5.5;
B double y = 10;
C boolean flag = true;
D String name = 123;
Correct Answer:  C. boolean flag = true;
EXPLANATION

Option C is correct. Option A causes a compilation error (cannot assign double to int). Option B works but there's implicit conversion. Option D causes a compilation error (cannot assign int to String).

Take Test
Q.880 Hard Basics & Syntax
What will be the output of: int x = 5; System.out.println(++x + x++);?
A 11
B 12
C 13
D 10
Correct Answer:  B. 12
EXPLANATION

++x increments x to 6 and returns 6 (pre-increment). Then x++ returns 6 and increments x to 7 (post-increment). So 6 + 6 = 12. The order of evaluation in expressions like this depends on operator precedence and associativity.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips