AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 11 - 19 of 19 questions

11

The width in bits of double primitive type in Java is --.

 

a

The width of double is platform dependent

b

128

c

64

d

8

correct answer b,d
12

Which of the following is true regarding source code file ?

a

A. It can have more than one public class

b

B. It can have more than one non public class and one public class

c

C. It cannot have non public class

d

D. None of the above

correct answer b
13

What is true regarding the following code in Student.Java ?

public class Student{ }

public class ABC { }

a

A. Compilation error

b

B. Runtime error

c

C. No error

d

D. None of the above

correct answer a

Source code file can have only one public class.

14

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
15

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
16

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
17

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
18

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
19

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