Home Subjects Java Programming Basics & Syntax

Java Programming
Basics & Syntax

Java OOP, collections, multithreading

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 71–80 of 100
Topics in Java Programming
Q.71 Medium Basics & Syntax
What is the output of: System.out.println("5" + 3 + 2);
A 10
B 532
C Error
D 7
Correct Answer:  B. 532
EXPLANATION

String concatenation: "5" + 3 becomes "53", then "53" + 2 becomes "532". Once a String is involved, + performs concatenation.

Take Test
Q.72 Easy Basics & Syntax
What will be the output: String s = "Hello"; System.out.println(s.charAt(1));
A H
B e
C l
D o
Correct Answer:  B. e
EXPLANATION

charAt() uses 0-based indexing. Index 1 refers to the second character, which is 'e' in "Hello".

Take Test
Q.73 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.74 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.75 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.76 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.77 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
Q.78 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.79 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.80 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
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