Govt. Exams
Entrance Exams
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.
++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.
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.
Child constructor implicitly calls super() first, executing Parent constructor. Output: Parent prints 'P', then Child prints 'C'.
Calling a method on a null reference throws NullPointerException. s.length() tries to invoke method on null, causing the exception.
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.
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.
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.
Both conditions are true: x == 0 (true) and x != 1 (true). The && (AND) operator returns true when both operands are true.
Local variables have scope limited to the method or code block in which they are declared. They cannot be accessed outside that block.