Home Subjects Java Programming Basics & Syntax

Java Programming
Basics & Syntax

Java OOP, collections, multithreading

34 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–34 of 34
Topics in Java Programming
Q.31 Easy Basics & Syntax
What will be the output of: boolean flag = true; System.out.println(!flag);
A true
B false
C !true
D Compilation error
Correct Answer:  B. false
EXPLANATION

The logical NOT operator (!) inverts the boolean value. !true becomes false.

Test
Q.32 Easy Basics & Syntax
What will be the output of the following code? int x = 5; x += 3; System.out.println(x);
A 3
B 5
C 8
D 53
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.

Test
Q.33 Easy Basics & Syntax
Which keyword is used to create a constant variable in Java?
A const
B constant
C final
D immutable
Correct Answer:  C. final
EXPLANATION

The 'final' keyword is used to declare constants in Java. Once assigned, the value cannot be changed.

Test
Q.34 Easy Basics & Syntax
Which of the following is the correct syntax to declare a variable in Java?
A int x = 10;
B int x: 10;
C x int = 10;
D int: x = 10;
Correct Answer:  A. int x = 10;
EXPLANATION

Java uses the syntax 'datatype variableName = value;' for variable declaration.

Test
IGET
IGET AI
Online · Exam prep assistant
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