Govt. Exams
Entrance Exams
Advertisement
Topics in Java Programming
What will be the output of: boolean flag = true; System.out.println(!flag);
Correct Answer:
B. false
EXPLANATION
The logical NOT operator (!) inverts the boolean value. !true becomes false.
What will be the output of the following code? int x = 5; x += 3; System.out.println(x);
Correct Answer:
C. 8
EXPLANATION
The += operator adds the right operand to the left operand. x += 3 is equivalent to x = x + 3, so 5 + 3 = 8.
Which keyword is used to create a constant variable in Java?
Correct Answer:
C. final
EXPLANATION
The 'final' keyword is used to declare constants in Java. Once assigned, the value cannot be changed.
Which of the following is the correct syntax to declare a variable in Java?
Correct Answer:
A. int x = 10;
EXPLANATION
Java uses the syntax 'datatype variableName = value;' for variable declaration.