Java Programming
Java OOP, collections, multithreading
212 Questions 10 Topics Take Test
Advertisement
Showing 201–210 of 212 questions
Q.201 Hard Basics & Syntax
What is the result of: System.out.println('A' + 'B');?
A AB
B 131
C Compilation error
D 131.0
Correct Answer:  B. 131
EXPLANATION

Characters are promoted to their integer ASCII values in arithmetic operations. 'A' has ASCII value 65 and 'B' has ASCII value 66, so 65 + 66 = 131.

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

++x increments x to 6 and returns 6 (pre-increment). Then x++ returns 6 and increments x to 7 (post-increment). So 6 + 6 = 12. The order of evaluation in expressions like this depends on operator precedence and associativity.

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

x++ uses current value (5) then increments, ++x increments first then uses value (7). Order of evaluation: 5 + 7 = 12. However, x becomes 7 after ++x.

Take Test
Q.204 Hard Basics & Syntax
Consider: class Parent { Parent() { System.out.println("P"); } } class Child extends Parent { Child() { System.out.println("C"); } } public static void main(String[] args) { new Child(); }
A C
B P
C P C
D C P
Correct Answer:  C. P C
EXPLANATION

Child constructor implicitly calls super() first, executing Parent constructor. Output: Parent prints 'P', then Child prints 'C'.

Take Test
Q.205 Hard Basics & Syntax
Which of the following will throw a NullPointerException? String s = null; System.out.println(s.length());
A s = null
B System.out
C s.length()
D println()
Correct Answer:  C. s.length()
EXPLANATION

Calling a method on a null reference throws NullPointerException. s.length() tries to invoke method on null, causing the exception.

Take Test
Advertisement
Q.206 Hard Basics & Syntax
What will be the output? class Test { public static void main(String[] args) { int x = 10; { int x = 20; System.out.println(x); } System.out.println(x); } }
A 10 20
B 20 10
C 20 20
D Compilation Error
Correct Answer:  B. 20 10
EXPLANATION

A block scope creates a new variable x = 20 which shadows the outer x. First print outputs 20, then the block ends, outer x (10) is printed.

Take Test
Q.207 Hard Basics & Syntax
Which statement about Java's garbage collection is true?
A Garbage collection is deterministic and happens at fixed intervals
B Garbage collection is non-deterministic and may never run
C Calling System.gc() guarantees immediate garbage collection
D Objects are garbage collected as soon as they go out of scope
Correct Answer:  B. Garbage collection is non-deterministic and may never run
EXPLANATION

Garbage collection in Java is non-deterministic. System.gc() is just a request, not a guarantee. Objects are eligible for GC when unreachable, but actual collection timing varies.

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

x++ returns 5 (then increments to 6), ++x increments to 7 and returns 7. Sum = 5+7 = 12. Note: Actual result may vary due to JVM optimization but typically 11 or 12.

Take Test
Q.209 Hard Basics & Syntax
Consider: int x = 0; System.out.println(x == 0 && x != 1); What is the output?
A true
B false
C Compilation error
D 1
Correct Answer:  A. true
EXPLANATION

Both conditions are true: x == 0 (true) and x != 1 (true). The && (AND) operator returns true when both operands are true.

Take Test
Q.210 Hard Basics & Syntax
What is the scope of a local variable in Java?
A Throughout the class
B Throughout the method or block where it is declared
C Throughout the package
D Throughout the entire program
Correct Answer:  B. Throughout the method or block where it is declared
EXPLANATION

Local variables have scope limited to the method or code block in which they are declared. They cannot be accessed outside that block.

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