Which of the following will compile and run without errors?
Answer: B
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.
Q.82Hard
What is the result of: System.out.println('A' + 'B');?
Answer: B
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.
Q.83Medium
Which method is called automatically when an object is garbage collected?
Answer: A
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.
Q.84Hard
What will happen in this code: int x = Integer.MAX_VALUE; x++;?
Answer: B
In Java, integer overflow wraps around. When an int exceeds Integer.MAX_VALUE (2147483647), it overflows and wraps to Integer.MIN_VALUE (-2147483648).
Q.85Easy
Which of the following is NOT a Java keyword?
Answer: C
'thread' is not a Java keyword. 'synchronized', 'volatile', and 'transient' are all valid Java keywords used for special purposes.
Advertisement
Q.86Easy
What is the output of: System.out.println(5 > 3 ? "Yes" : "No");?
Answer: C
This uses the ternary operator (conditional operator). The condition 5 > 3 is true, so it returns the value after the '?', which is "Yes".
Q.87Easy
Consider the following code snippet. What is the primary purpose of the 'final' keyword when applied to a class in Java?
Answer: B
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.
Q.88Easy
Which of the following statements about Java's garbage collection is TRUE?
Answer: C
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.
Q.89Medium
What will be the output of the following code?
String str1 = "Hello";
String str2 = new String("Hello");
System.out.println(str1 == str2);
Answer: B
The '==' operator compares object references, not content. str1 refers to the string pool while str2 is a new object in heap memory, hence they have different references.
Q.90Medium
Consider a scenario where you need to create a variable that can hold references to objects of any type. Which of the following approaches would be most appropriate in Java 2024 standards?
Answer: B
Using generics with wildcards (List<?>) is the safest and most type-safe approach to handle objects of any type in modern Java. The 'var' keyword is also acceptable but wildcards provide better type checking.
Q.91Medium
Which of the following correctly demonstrates method overloading in Java?
Answer: B
Method overloading requires methods with the same name but different parameter types or number of parameters. Option A has different return types (not sufficient), C has different access modifiers (not overloading), D has different case names (different methods).
Q.92Easy
What will happen when you execute the following code?
int[] arr = new int[5];
System.out.println(arr[5]);
Answer: C
An array of size 5 has valid indices from 0 to 4. Accessing arr[5] throws ArrayIndexOutOfBoundsException at runtime because index 5 is out of bounds.
Q.93Hard
In the context of Java 2024-25 exam pattern, which statement about the enhanced 'var' keyword (local variable type inference) is INCORRECT?
Answer: B
'var' cannot be used in lambda expression parameters or method parameters. It's restricted to local variables with explicit initialization. Options A and C are correct features of 'var'.
Q.94Medium
Consider a real-world scenario where you need to implement a logging system. Which access modifier would you use for internal helper methods that should not be accessible outside the class?
Answer: C
'private' access modifier restricts the method to be accessible only within the same class, making it ideal for internal helper methods. This follows encapsulation principles.
Q.95Medium
Which of the following statements about Java's String class is TRUE?
Answer: B
The String class is declared as 'final' in Java, which prevents inheritance and ensures immutability. Strings are immutable, 'new' creates objects in heap not pool, and StringBuilder is generally better for concatenation.
Q.96Hard
What will be the result of executing the following code?
boolean result = (5 > 3) && (010 > 5);
System.out.println(result);
Answer: C
Although the '&&' operator has short-circuit evaluation, Java evaluates both operands in this case. The first condition (5 > 3) is true, but the second (010) causes ArithmeticException due to division by zero.
Q.97Medium
In Java, what is the relationship between an interface and a class in terms of implementation?
Answer: A
Java supports multiple interface implementation but single class inheritance. A class uses 'implements' keyword for interfaces and 'extends' for classes. This is a fundamental OOP concept.
Q.98Easy
Consider the following code. What will be printed?
String s = "Java";
s = s.concat(" Programming");
System.out.println(s.length());
Answer: C
"Java" has 4 characters. After concatenation with " Programming" (12 characters including space), the total length is 4 + 13 = 17 characters.
Q.99Easy
Which of the following is a valid declaration of a two-dimensional array in Java that can store 3 rows and 4 columns of integers?
Answer: D
All three declarations are syntactically valid in Java and represent the same 2D array structure. The position of brackets doesn't matter for 2D array declaration - they all create a 3x4 integer array.
Q.100Easy
Which of the following is NOT a pillar of Object-Oriented Programming?
Answer: C
The four pillars of OOP are Abstraction, Encapsulation, Inheritance, and Polymorphism. Compilation is a process, not a pillar of OOP.