java-questions-4

By | August 4, 2019

1 Which one of the following represents legal flow control statements?

a. break;

b. break();

c. continue(inner);

d. exit();

 

2. Predict the output from below java program.

Options:

A. Got the exception 10

B. Go the exception 0

C. Compile time error

D. Run-time error

C

 

3. Output of below java program.

Options:

A. Compile error

B. Runtime error

C. ArrayIndexOutOfBoundsException

D. Array is printed

E. Error code is printed.

A.

Error message: Unreachable catch block for ArrayIndexOutOfBoundsException. It is already handled by the catch block for Exception

4. Predict the output of below program.

Options:

A. Constructor called
Method called

B. Compilation error

C. Runtime error

D. None of these

A

5. What is the output of the following program.

Options:

A. Compilation error due to line1

B. Compilation error due to line2

C. Compilation errors due to line1 and line2

D. 246

C. Compilation errors due to line1 and line2

Error messages:

Cannot cast from int to String

Cannot cast from String to int

6. What is the output of the following program?

Options:

A. 444.35

B. 444

C. Compilation error

D. Runtime error

C. Compilation error

Error:  Type mismatch: cannot convert from double to int

7. What is the output of the following program?

Options:

A. 10 20 30 40 50

B. 10 20 30

C. Compilation error

D. Runtime error

A

8. What is the output of the following program?

Options:

A. 11 10 22 5 12 2

B. 2 12 5 22 10 11

C. 22 12 11 10 5 2

D. 2 5 10 11 12 22

D

Priority queue:

An unbounded priority queue based on a priority heap. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException).

9. Which of the following statements are true?

i) We cannot use abstract classes to instantiate objects directly.

ii) The abstract methods of an abstract class must be defined in its subclass

iii) We cannot declare abstract constructors

iv) We may declare abstract static methods

Options:

A. i only

B. ii only

C. i and ii only

D. i, ii and iii only

10. What is the output of the following program?

Options: 

A. 4

B. 5

C. 6

D. Compilation error

C

Leave a Reply

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