Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 931–940 of 958 questions
Q.931 Easy Basics & Syntax
Which of the following is the correct syntax for a multi-line comment in Java?
A // This is a comment
B /* This is a comment */
C
D # This is a comment
Correct Answer:  B. /* This is a comment */
EXPLANATION

Multi-line comments in Java use /* */ syntax. Single-line comments use //. Other syntaxes are for different languages.

Take Test
Q.932 Medium Basics & Syntax
What is the output of: System.out.println(10 * 2 / 5 * 2);
A 8
B 4
C 16
D 2
Correct Answer:  A. 8
EXPLANATION

Operators *, / have same precedence and are evaluated left to right: ((10 * 2) / 5) * 2 = (20 / 5) * 2 = 4 * 2 = 8.

Take Test
Q.933 Medium Basics & Syntax
Which of the following statements will compile successfully?
A byte b = 300;
B byte b = (byte) 300;
C int i = 'a';
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

Option A fails (300 exceeds byte range). Option B works with explicit casting. Option C works (char to int conversion is implicit).

Take Test
Q.934 Medium Basics & Syntax
What is the result of: System.out.println(true && false || true);
A true
B false
C Error
D null
Correct Answer:  A. true
EXPLANATION

&& has higher precedence than ||. So: (true && false) || true = false || true = true.

Take Test
Q.935 Easy Basics & Syntax
What will be printed? float f = 5.5f; System.out.println(f);
A 5.5
B 5.50
C Error
D 5
Correct Answer:  A. 5.5
EXPLANATION

The 'f' suffix indicates a float literal. The output will be 5.5 (trailing zeros are not shown in standard printing).

Take Test
Advertisement
Q.936 Medium Basics & Syntax
Which of the following correctly represents a long literal in Java?
A long num = 1000000;
B long num = 1000000L;
C long num = 1000000l;
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

Both 'L' and 'l' suffixes are valid for long literals in Java, though 'L' is preferred as it's less confusing with '1'.

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

++x increments x to 6 and uses it, then x++ uses 6 and increments to 7. So 6 + 6 = 12.

Take Test
Q.938 Medium Basics & Syntax
What will be the output: System.out.println('A' + 'B');
A AB
B 131
C Error
D 2
Correct Answer:  B. 131
EXPLANATION

Characters are treated as their ASCII values in arithmetic operations. 'A' (65) + 'B' (66) = 131.

Take Test
Q.939 Easy Basics & Syntax
Which of the following is a valid variable name in Java?
A 123abc
B _myVar
C my-Var
D class
Correct Answer:  B. _myVar
EXPLANATION

Variable names must start with a letter, underscore (_), or dollar sign ($). They cannot start with digits, contain hyphens, or be reserved keywords.

Take Test
Q.940 Easy Basics & Syntax
Which keyword is used to prevent a class from being inherited?
A static
B abstract
C final
D private
Correct Answer:  C. final
EXPLANATION

The 'final' keyword prevents a class from being extended/inherited. A final class cannot have subclasses.

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