AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 141 - 150 of 150 questions

141

Which of the following statements is false?

a

A. A set is a collection that does not allow duplicates.

b

B. A map can store duplicate values.

c

C. A list is a collection that is ordered by index.

d

D. A list is a collection that cannot have duplicates.

correct answer d
142

Which of the following statements is not true about the hashcode?

a

A. The hashcode values of two equal objects must be equal.

b

B. The hashcode values of two unequal objects must be unequal.

c

C. If the hashcode values of two unequal objects are always unequal, it improves the performance.

d

D. A function that always returns a constant is not a very efficient function.

correct answer b
143

Consider the following code fragment:

1. int i = 5;

2. printIt(i);

3. void printIt(Integer wi) {

4. int j = wi;

5. System.out.println("The value is: " + j);

6. }

What is the output of this code?

a

A. The value is: 5

b

B. Compiler error at line 3

c

C. Compiler error at line 2

d

D. Runtime error

correct answer a
144

Which of the following classes implements the java.util.List interface?

a

A. Java.util.HashMapTable

b

B. Java.util.LinkedList

c

C. Java.util.HashTable

d

D. Java.util.OrderedList

correct answer b
145

Consider the following code fragment:

1. package RobotDrivers ;

2. import robots.*;

3. public class RobotPlayer extends FunnyRobot {

4. static int i =5;

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

6. i = 6;

7. RobotPlayer rp = new RobotPlayer();

8. rp.dance();

9. }

10. }

Which of the following statements is true about this code fragment?

a

A. The code will compile and execute correctly and generate the output: The funny robot is dancing!.

b

B. There would be a compiler error at line 7 because the method dance() is protected and the classes RobotPlayer and FunnyRobot are in different packages.

c

C. There would be a compiler error at line 6.

d

D. The code will compile but generate a runtime exception.

correct answer a
146

Consider the following code fragment:

1. class MyClass {

2. public void message (int i) {

3. public int j= i;

4. System.out.println("Value of j: " + j);

5. }

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

7. MyClass ma = new MyClass();

8. ma.message(15);

9. }

10. }

Which of the following statements is true about this code?

a

A. The code will compile and execute fine, and the output will be Value of j: 15

b

B. Line 2 will generate a compiler error.

c

C. The code will compile but will give an error at execution time.

d

D. None of the above

correct answer b
147

Which of the following statements is true?

a

A. The final variable may only be used with a variable or a method.

b

B. The final variable may not be copied to a file during object serialization.

c

C. The final method may not be overridden.

d

D. The class that has a final method may not be extended.

correct answer c
148

Which of the following statements is true about the static modifier?

a

A. A static variable cannot change its value.

b

B. A static method cannot be overridden to be non-static.

c

C. A static method is often overridden in a non-Java language and exists outside of JVM.

d

D. The static code lies outside of any class.

correct answer b
149

Consider the following code fragment:

1. class MySuperClass {

2. static void message() {

3. System.out.println("From the super class!");

4. }

5. }

6. public class MySubClass extends MySuperClass {

7. void message() {

8. System.out.println("From the subclass!");

9. }

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

11. MySubClass mysub = new MySubClass(); 12. mysub.message();

13. }

14. }

Which of the following modifiers placed in the beginning of line 7 will make the code compile and execute without error?

a

A. Static

b

B. Public

c

C. Protected

d

D. Transient

correct answer a
150

Assume that a variable exists in a class and that the variable must not be copied into a file when the object corresponding to this class is serialized. What modifier should be used in the declaration of this variable?

a

A. Private

b

B. Protected

c

C. Native

d

D. Transient

correct answer d
Select a company to compare with

vs

Similar Companies