Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Multiple choice questions

1. What will be the order of binary search?

a) O (n) b) O (n2)

C) O (n!) d) O (logn)

2. The algorithm of order O (n logn) is called as?

a) Linear algorithm b) Exponential algorithm

c) Super linear algorithm d) Factorial algorithm

3. What is the range of the int data type?

a) –2,147,483,648 to 2,147,483,647 b) -2,147,483,647 to 2,147,483,648

c) -32,768 to 32,767 d) -32,767 to 32,768

4. How many types of JDBC drivers are available?


a) 3 b) 4

c) 5 d) 6

5. What is used to convert the byte-oriented stream into character-oriented stream?


a) Console b) Scanner

c) InputStreamReader d) DataInputStream

6. Which class can be used to read data line by line using the readLine() method?

a) BufferedReader b) InputStreamReader

c) DataInputStream d) None of the above

7. Generally string is a sequence of characters, but in java, string is an _______.


a) Variable b) Class

c) Package d) Object

8. Select the packages in which JDBC classes are defined?

a) jdbc and javax.jdbc b) rdb and javax.rdb

c) jdbc and java.jdbc.sql d) java.sql and javax.sql


9. Analyze the following code and choose the correct answer.

int[] arr = new int[5];

arr = new int[6];

a) The code has compile errors because the variable arr cannot be changed once it is assigned.

b) The code has runtime errors because the variable arr cannot be changed once it is assigned.

c) The code can compile and run fine. The second line assigns a new array to arr.

d) The code has compile errors because we cannot assign a different size array to arr.

10. What will be the output?

public class Test{

public static void main(String[] args){

int[] a = new int[4];

a[1] = 1;

a = new int[2];

System.out.println("a[1] is " + a[1]);

a) The program has a compile error because new int[2] is null

b) The program has a runtime error because a[1] is not referenced

c) a[1] is 0

d) a[1] is 1

11. What is the value of a[1] after the following code is executed?
int[] a = {0, 2, 4, 1, 3};

for(int i = 0; i < a.length; i++)

a[i] = a[(a[i] + 3) % a.length];

A) 0

B) 1

C) 2

D) 3

E) 4

12. What would be the result of attempting to compile and run the following code?

public class HelloWorld{

public static void main(String[] args){

double[] x = new double[]{1, 2, 3};

System.out.println("Value is " + x[1]);

a) The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should
be replaced by {1, 2, 3}.

b) The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should
be replaced by new double[3]{1, 2, 3};

c) The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should
be replaced by new double[]{1.0, 2.0, 3.0};

d) The program compiles and runs fine and the output is 2.0
13. What is the output for the below code?

public class Test{

public static void main(String[] args){

int i = 010;

int j = 07;

System.out.println(i);

System.out.println(j);

a) 8

b) 10

c) Compilation fails with an error at line 3

d) Compilation fails with an error at line 5

14 .What will be the output for the below code?

public class Test{

public static void main(String[] args){

byte i = 128;

System.out.println(i);

a) 128
b) 0

c) Compilation fails with an error at line 3

d) Compilation fails with an error at line 4

15.What will be the output for the below code ?

public class Test{

int i=8;

int j=9;

public static void main(String[] args){

add();

public static void add(){

int k = i+j;

System.out.println(k);

a) 17

b) 0

c) Compilation fails with an error at line 5

d) Compilation fails with an error at line 8

You might also like