AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 31 - 37 of 37 questions

31

Which of the following is an invalid variable name in Java?

a

A. $char

b

B. 1mynumber

c

C. caseof

d

D. _int

correct answer b
32

Consider the following piece of code:

float lu luckyNumber = 1.25;

System.out.println ( "The value of luckyNumber: " + luckyNumber );

What is the result?

a

A. The value of lucky number::

b

B. The value of lucky number: 1.25

c

C. The code would not compile

d

D. The code will compile but will give a runtime error.

correct answer c
33

Look this code:

1. class CodeWalkOne {

2. public static void main(String [] args) {

3. int [] counts = {1,2,3,4,5};

4. counts[1] = (counts[2] == 2) ? counts[3] : 99;

5. System.out.println(counts[1]);

6. }

7. }

What is the result?

a

A. Compilation fails on line 4.

b

B. 3

c

C. 4

d

D. 99

correct answer d
34

Consider the following code fragment:

1. public class Question{

2. public static void main(String[] args) {

3. byte x = 21;

4. byte y = 13;

5. int z = x^y;

6. System.out.println(z);

7. }

8. }

What is the result of this code fragment?

a

A. 24

b

B. 29

c

C. 21

d

D. A compiler error occurs at line 5.

correct answer a
35

Which of the following expressions is legal?

a

A. int x=9;

b

B. int y=!x;

c

C. double z=9.00>>2;

d

D. int i=^7;

correct answer a
36

Which of the following statements would not produce the compile error?

a

A. char my_char='c';

b

B. char your_char='int';

c

C. char what='hello';

d

D. char what_char="L";

correct answer a
37

Which of the following statements would not produce the compile error?

a

A. char my_char='c';

b

B. char your_char='int';

c

C. char what='hello';

d

D. char what_char="L";

correct answer a
Select a company to compare with

vs

Similar Companies