Section 8 Quiz
1. Which two are limitations of an array of primitives (ie: int[] x)?
(Pilih semua jawaban yang benar)
The size of the array is fixed during array creation and cannot grow once initialized. (*)
You need to create your own methods to manipulate array contents. (*)
You cannot overwrite the contents of an array once initialized.
You can create only one array in a class.
Correct
(1/1) Point
2. Which is NOT a benefit of ArrayList class?
You can remove all of the elements of an ArrayList with a method.
An ArrayList grows as you add elements.
You can use an ArrayList list to store Java primitive values (like int). (*)
An ArrayList shrinks as you remove elements.
Correct
(1/1) Point
3. The size of an ArrayList can grow as needed.
benar (*)
Palsu
Correct
(1/1) Point
4. If the try block succeeds then no exception has occurred.
benar (*)
Palsu
Correct
(1/1) Point
5. What is the output?
int[] array = {10, 20, 30};
int b = 0;
try{
System.out.println("1");
int c = (array[3] / b);
System.out.println("2");
}
catch(ArithmeticException ex){
System.out.println("Arithmetic Exception");
}
catch(ArrayIndexOutOfBoundsException ex){
System.out.println("Array index out of bounds");
}
1
Arithmetic Exception
1
Array index out of bounds (*)
1
2
Array index out of bounds
1
2
Array index out of bounds
Correct
6. Which code goes in the try block?
Any code that is likely to cause an exception. (*)
Any code that is safe from an exception.
Any code that can handle an exception.
Any code that is likely to print the exception details.
Correct
(1/1) Point
7. Which two are valid array declarations?
(Pilih semua jawaban yang benar)
int size[]; (*)
int[] size; (*)
int array size;
[]int size;
Correct
(1/1) Point
8. An array allows you to create a single identifier that can be used to organize many items of the same data type.
benar (*)
Palsu
Correct
(1/1) Point
9. What is an array?
An array is a way to create multiple copies of a single value.
An array is a Java primitive type.
An array is an indexed container that holds a set of values of a single type. (*)
An array is an indexed container that holds a set of values of a multiple types.
Correct
(1/1) Point
10. The Java compiler does not check for an ArrayIndexOutOfBoundsException during the compilation of a program containing arrays.
benar (*)
Palsu
Correct
11. Given:
int x[];
What is the value of x?
null (*)
1
0
Some random number.
Correct
(1/1) Point
12. What is the output?
int[] arr = new int[5];
for(int i=0; i<arr.length; i++){
arr[i] = i;
}
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i]);
}
12345
123
01234 (*)
012345
Correct
(1/1) Point
13. What are two advantages of adding print statements for debugging?
(Pilih semua jawaban yang benar)
You can identify runtime errors.
You can identify which methods have been called. (*)
You can identify the order in which methods have been called. (*)
You can identify compilation errors.
Correct
(1/1) Point
14. Using a Java debugger, you can set breakpoints and trace through a program one line at a time.
benar (*)
Palsu
Correct
(1/1) Point
15. Which is not a compilation error?
int x=2
y = 3 + * 5;
int y;
y++; (*)
x = ( 3 + 5;
Correct
Posting Komentar untuk "Section 8 Quiz"