Java Programming
Java OOP, collections, multithreading
Showing 471–476 of 476 questions
What is the output of: System.out.println(5 > 3 ? 'A' : 'B');
Correct Answer:
A. A
EXPLANATION
The ternary operator (?:) evaluates the condition (5 > 3, which is true) and returns the first value 'A'.
Which operator has the highest precedence in Java?
Correct Answer:
C. () []
EXPLANATION
Parentheses () and array access [] have the highest precedence in Java. Multiplication, division, and modulo come next, followed by addition and subtraction.
What is the output of: System.out.println(10 / 3);
Correct Answer:
B. 3
EXPLANATION
When both operands are integers, the division result is an integer. 10 / 3 = 3 (integer division, not floating-point).
Which of the following will compile without error? public static void main(String args[]) { int x = 10; final int y = 20; y = 30; }
Correct Answer:
B. No, compilation error on y = 30
EXPLANATION
Once a final variable is assigned, it cannot be reassigned. The line 'y = 30;' will cause a compilation error.
What is the size of 'char' data type in Java?
Correct Answer:
B. 2 bytes
EXPLANATION
The 'char' data type in Java is 2 bytes (16 bits) because it uses Unicode character encoding.
Which of the following is NOT a primitive data type in Java?
Correct Answer:
C. String
EXPLANATION
String is a non-primitive (reference) data type in Java. Primitive types include int, boolean, double, float, char, long, short, byte.