15-what is the output of this program?
Class output {
public static void main(String args[])
{
int arr[] = {1, 2, 3, 4, 5};
for ( int i = 0; i < arr.length - 2; ++i)
system.out.println(arr[i] + " ");
}
}
a) 1 2
b) 1 2 3
c) 1 2 3 4
d) 1 2 3 4 5
answer: b
16. in java arrays are
a.objects
b.object references
c.primitive data type
d. none of this
ans: a
17. 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[];
ans: b
18-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
ans: a
19-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.