Java interview questions

Java Interview Questions:

1. Method overloading:

a. Compile time exception
b. Run rime exeption
c. String-null
d. Integer-null
Ans: a

2. How to find sum of an array?



Sum of an array is: 150
Lenght of an array is: 5

3: Which of the following access specifier makes a declaration that is accessible to itself?

a. public
b. private
c. protected
d. privately
Ans: b

4: Which of the following statement is true with respect to class and members of a class?

a. It is mandatory for every class to declare a main method inside it.
b. It is mandatory to specify return type along with method definition in a class.
c. It is mandatory to initiate member variables while declaring them in a class.
d. It is mandatory to use an access specifier along with declaring statement of a member variable.
Ans: Will reveal soon.

5: What is the output of below code?

a. output is: zero
output is: one
b. Runtime error
c. output is: zero
output is: one
output is: null
output is: null
d. Compilation error
Ans: C

6: What is the output of below code?


a. output is: zero
output is: one
b. Compilation error
c. Runtime error
d. ArrayIndexOutOfBounds Exception

Ans: a

7. Write a code to find the sum of numbers between two given positions in an array.



Array length is: 20
n1 position is: 4
n1 position is: 14
Total sum is: 450

8. Write a code to find out first max number and then first minimum number and so on in a sorted/unsorted array?



9. What is the output for below code snippet?


a. 10 20
b. 20 40
c. 10 40
d. 20 80

Ans: c

10. What is the output of below code snippet? String manipulations.


a. First Second
b. Selenium99
c. First Second Selenium99
d. Selenium99 First Second



10.1. Find the output. String manipulations.


a. false

b. true


d. selenium99


Ans: c

Tags: Java interview questions