Вы находитесь на странице: 1из 6

Which one of the following is a valid statement?

A. char[] c = new char();


B. char[] c = new char[5];
C. char[] c = new char(4);
D. char[] c = new char[];

Answer: Option B

What is the result of compiling and running the following code?

public class Test{


public static void main(String[] args){
int[] a = new int[0];
System.out.print(a.length);
}
}

A. 0

B. Compilation error, arrays cannot be initialized to zero size.

C. Compilation error, it is a.length() not a.length

D. None of the above

Answer: Option A

What will be the output?

public class Test{


public static void main(String[] args){
int[] x = new int[3];
System.out.println("x[0] is " + x[0]);
}
}

A. The program has a compile error because the size of the array wasn't specified when declaring
the array.

B. The program has a runtime error because the array elements are not initialized.
C. The program runs fine and displays x[0] is 0.

D. The program has a runtime error because the array element x[0] is not defined.

Answer: Option C

When you pass an array to a method, the method receives ________ .

A. A copy of the array.

B. A copy of the first element.

C. The reference of the array.

D. The length of the array.

Answer: Option C

Which will legally declare, construct, and initialize an array?

A. int [] myList = {};

B. int [] myList = (5, 8, 2);

C. int myList [] [] = {4,9,7,0};

D. int myList [] = {4, 3, 7};

Answer: Option D

Which of these is necessary to specify at time of array initialization?


a) Row
b) Column
c) Both Row and Column
d) None of the mentioned

Answer: a
Which of these operators is used to allocate memory to array variable in Java?
a) malloc
b) alloc
c) new
d) new malloc

Answer: c

Datatypes

Java is a ........... language.


A. weakly typed

B. strongly typed

C. moderate typed

D. None of these

Answer: Option B

How many primitive data types are there in Java?

A. 6

B. 7

C. 8

D. 9

Answer: Option C

In Java byte, short, int and long all of these are


A. signed
B. unsigned

C. Both of the above

D. None of these
Answer: Option A

Size of int in Java is


A. 16 bit

B. 32 bit

C. 64 bit

D. Depends on execution environment


Answer: Option B

The smallest integer type is ......... and its size is ......... bits.

A. short, 8

B. byte, 8

C. short, 16

D. short, 16
Answer: Option B

Size of float and double in Java is

A. 32 and 64

B. 64 and 64

C. 32 and 32

D. 64 and 32
Answer: Option A

Automatic type conversion in Java takes place when

A. Two type are compatible and size of destination type is shorter than source type.

B. Two type are compatible and size of destination type is equal of source type.

C. Two type are compatible and size of destination type is larger than source type.

D. All of the above


Answer: Option C

Which of the following automatic type conversion will not be possible?

A. short to int

B. byte to int

C. int to long

D. long to int
Answer: Option D

In Java, the word true is ................


A. A Java keyword

B. A Boolean literal

C. Same as value 1

D. Same as value 0
Answer: Option B

Which one is a valid declaration of a boolean?


a) boolean b1 = 1;
b) boolean b2 = ‘false’;
c) boolean b3 = false;
d) boolean b4 = ‘true’

Answer: c

Вам также может понравиться