Java Programming - Arrays Questions And Answers

Java Programming : Java Arrays

This is Java Programming Section with Multiple Choice Questions on Java Arrays. Single dimensional and Multi dimensional Arrays Questions with Explanations for Java Freshers.
1. Which of these function is used to allocate memory to array variable in Java?
[A] malloc
[B] alloc
[C] new
[D] calloc
Loading...
2. 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
Loading...
3. What will be printed using following code block?
int[] a = {0,1,2,3,4,5,6,7};
System.out.println(a.length);
[A] 6
[B] 7
[C] 8
[D] 9
Loading...
4. What will happen when following Java code block is compiled and run?

public class A {

public static void main(String argv[]){

int ary[]=new int[]{1,2,3};

System.out.println(ary[1]);

}

}
[A] 1
[B] Compilation Error: Incorrect Syntax
[C] 2
[D] Compilation Error: size of array must be defined
Loading...
5.
What will happen if following code block is compiled/run?
int[] iArray = new int[10];

iArray.length = 15;

System.out.println(iArray.length);
[A] Prints 10
[B] Prints 15
[C] Compilation Error
[D] Run Time Error
Loading...
6. 6.Will the following program compile successfully ?

class MyArray

{

public static void main(String[] args)

{

int arr1[]=new int[2]{1,2};

int arr2[]=new int[]{1,2,3};

}

}
[A] Yes
[B] No
Loading...
7.
Given a one dimensional array arr, what is the correct way of getting the number of elements in arr.

Select the one correct answer.
[A] arr.length
[B] arr.length - 1
[C] arr.size
[D] arr.size - 1
Loading...
8. 8.What is the output of the following program?

class MyMethod

{

static int func( int i)

{

return ++i;

}

public static void main(String[] args)

{

int i=0;

int j=func(i++) + i + func(++i);

System.out.println(i);

System.out.println(j);

}

}
[A] 5 2
[B] 2 5
[C] 2 6
[D] 2 4
Loading...
9. What is the output of this program?

class evaluate {

public static void main(String args[])

{

int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};

int n = 6;

n = arr[arr[n] / 2];

System.out.println(arr[n] / 2);

}
}
[A] 3
[B] 0
[C] 6
[D] 1
Loading...
10. What is the output of this program?
class array_output {
public static void main(String args[])
{
char array_variable [] = new char[10];
for (int i = 0; i < 10; ++i) {
array_variable[i] = 'i';
System.out.print(array_variable[i] + "");
}
}
}

[A] 1 2 3 4 5 6 7 8 9 10
[B] 0 1 2 3 4 5 6 7 8 9 10
[C] i j k l m n o p q r
[D] i i i i i i i i i i
Loading...

Are these questions helpful for you?



Comments: (Your feedback is valuable to us)

how will 1 year ago Reply

how will you convert benzene into glyoxal?