Java Programming
Java OOP, collections, multithreading
476 Questions 10 Topics Take Test
Advertisement
Showing 461–470 of 476 questions
Q.461 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.462 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.463 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.464 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.465 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
Advertisement
Q.466 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.467 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.468 Medium Basics & Syntax
Which of the following is the correct way to declare and initialize an array in Java?
A int array[5] = {1, 2, 3, 4, 5};
B int[] array = {1, 2, 3, 4, 5};
C int array = [1, 2, 3, 4, 5];
D array[5] int = {1, 2, 3, 4, 5};
Correct Answer:  B. int[] array = {1, 2, 3, 4, 5};
EXPLANATION

The correct syntax is 'datatype[] arrayName = {elements};' or 'datatype[] arrayName = new datatype[size];'

Take Test
Q.469 Medium Basics & Syntax
Identify the output: System.out.println("Java".length());
A 4
B 5
C Compilation error
D null
Correct Answer:  A. 4
EXPLANATION

The length() method returns the number of characters in the string "Java", which is 4 characters.

Take Test
Q.470 Medium Basics & Syntax
Which statement is correct about Java variables?
A Variable names are case-sensitive
B Variable names can start with a digit
C Variable names can contain spaces
D Variable names can use special characters like @, #
Correct Answer:  A. Variable names are case-sensitive
EXPLANATION

Java variable names are case-sensitive. 'age' and 'Age' are different variables. Names cannot start with digits, cannot contain spaces, and special characters are not allowed.

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