15 questions
Which of the following is FALSE about arrays on Java
A java array is always an object
Length of array can be changed after creation of array
Arrays in Java are always allocated on heap
Find the output
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
Compile error
Exception
Garbage Value
Garbage Value
0
0
Find the output
class Test {
public static void main(String args[]) {
int arr [ ] = new int[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
Compile error
Exception
Garbage Value
Garbage Value
0
0
Output of following Java program?
class Test{
public static void main (String[] args) {
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (arr1 == arr2)
System.out.println("Same");
else
System.out.println("Not same");
}}
Same
Not same
Error
class Test{
public static void main (String[] args) {
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if(arr1.equals(arr2))
System.out.println("Same");
else
System.out.println("Not same");
}}
Same
Not same
Error
What is the length of the following array: byte[] data = { 12, 34, 9, 0, -62, 88 };
1
5
6
12
Does a programmer always know how long an array will be when the program is being written?
Yes---the program will not compile without the length being declared.
No---the array object is created when the program is running, and the length might change from run to run.
Yes---otherwise the program will not run correctly.
No---arrays can grow to whatever length is needed.
class Demo1
{
public static void main(String args[])
{
int i[] = new int[0];
System.out.println(i[0]);
}
}
0
Garbage Value
Exception
class Demo1
{
public static void main(String args[])
{
int i[] = new int[10];
System.out.println(i[10]);
}
}
0
Garbage Value
Out-of-bounds exception
Error
Which search algorithm is the easiest to understand?
Binary
Sequential
If the data is in order the best search to use would be a
Binary Search
Sequential Search
ar
, given the following declaration:int[] ar = {2, 4, 6, 8 }
0, 1, 2, 3
1, 2, 3, 4
0, 2, 4, 6