Java questions – Part 5

By | August 13, 2020

1 What is the output of below code snippet?

Options:

A. “123451234512345”
B. Prints a negative integer value
C. “12345100000”
D. Compilation error

D

Explanation: Exception in thread “main” java.lang.Error: Unresolved compilation problem:
The literal 123451234512345 of type int is out of range

2. Given the following definitions, which of these expressions will NOT evaluate to true?

Options:

A. b1 | !b2
B. (i1 ^ 12) < 4
C. i2 & b1
D. (i1 | i2) == 3

C

Explanation:

3. What is the output of this code?

Options:

A. truefalse
B. Compilation error
C. truetrue
D. falsetrue

C

4 What is the output of below code?

Options:

A. HelloHello
B. Hello!Hello!
C. Runtime error
D. Hello!Hello

B

5. Predict the output of below program.

Options:

A. CDE
B. CD
C. C
D. “abcde”

D

Explanation:

Even though we have performed operations like trim and uppercase on “s1”, we didn’t assign back it to “s1”.

6. Which method(s) compile properly from the below code snippet.

Options:

A. P1
B. P1 and P2
C. P2, P3 and P4
D. P1 and P4
E. No method compiles

D

Explanation:

Recommended Posts: 

How to find common elements in arraylists java

TestNG

How to find the third largest number in an array in Java

Real-time selenium interview questions

How to get last 4 chars from String

Hashset and LinkedHashset differences in java

 

Tags: java questions

Leave a Reply

Your email address will not be published. Required fields are marked *