0% found this document useful (0 votes)
75 views

A2119680103 - 21760 - 3 - 2018 - Datatypes and Arrays

The document contains questions and answers related to arrays and datatypes in Java. Some key points: - Option B of the first question is a valid way to declare and initialize a char array of size 5. - The output of the code provided would be 0, as initializing an array of size 0 prints its length, which is 0. - The code provided would display "x[0] is 0" without errors, as array elements are initialized to default values (0 for int). - When an array is passed to a method, it passes the reference of the array rather than a copy. - Option D is a valid way to declare, construct and initialize an array by specifying

Uploaded by

Rishab Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

A2119680103 - 21760 - 3 - 2018 - Datatypes and Arrays

The document contains questions and answers related to arrays and datatypes in Java. Some key points: - Option B of the first question is a valid way to declare and initialize a char array of size 5. - The output of the code provided would be 0, as initializing an array of size 0 prints its length, which is 0. - The code provided would display "x[0] is 0" without errors, as array elements are initialized to default values (0 for int). - When an array is passed to a method, it passes the reference of the array rather than a copy. - Option D is a valid way to declare, construct and initialize an array by specifying

Uploaded by

Rishab Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 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

You might also like