AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 121 - 130 of 150 questions

121

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
122

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
123

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
124

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
125

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
126

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
127

Which method is used to perform interthread communications?

a

A. yield ( )

b

B. sleep (..)

c

C. notify ( )

d

D. wait ( )

correct answer a
128

Which of the following methods is not defined in the Thread class?

a

A. yield ( )

b

B. sleep (..)

c

C. run ( )

d

D. wait ( )

correct answer d
129

What would happen when a thread executes the following statement in its run() method?

sleep(500);

a

A. It is going to stop execution and restart execution exactly after 500 milliseconds.

b

B. It is going to stop execution and restart execution not earlier than 500 milliseconds.

c

C. It will result in compiler error because sleep ( ) method cannot be called inside run ( ) method.

d

D. It will result in compiler error because the sleep ( ) method does not take any argument.

correct answer b
130

Consider the following code fragment:

1. public class ThreadTest {

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

3. Counter ct = new Counter();

4. ct.start();

5. System.out.println("The thread has been started");

6. }

7. }

8. class Counter extends Thread {

9. protected void run() {

10. System.out.println("Hello");

11. }

12. }

What would be the output of this code fragment?

a

A. The thread has been started.

     Hello

b

B. Hello

    The thread has been started.

c

C. Either A or B

d

D. Compiler error on line 9

correct answer d
Select a company to compare with

vs

Similar Companies