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

Examenjava 8

The document discusses Java arrays and ArrayLists. It provides true/false and multiple choice questions about declaring and initializing arrays and ArrayLists, accessing elements, exceptions like ArrayIndexOutOfBoundsException, and exception handling. The questions are answered correctly, indicating an understanding of basic array and exception concepts in Java.

Uploaded by

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

Examenjava 8

The document discusses Java arrays and ArrayLists. It provides true/false and multiple choice questions about declaring and initializing arrays and ArrayLists, accessing elements, exceptions like ArrayIndexOutOfBoundsException, and exception handling. The questions are answered correctly, indicating an understanding of basic array and exception concepts in Java.

Uploaded by

XIOMARA JIMÉNEZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. How could you declare an ArrayList so that it can store true or false values?

ArrayList<Boolean> arrList = new ArrayList<>(); (*)


ArrayList<true, false> arrList = new ArrayList<>();
ArrayList<boolean> arrList = new ArrayList<>();
ArrayList<True, False> arrList = new ArrayList<>();
Correct
(1/1) Points
2. You can access elements in an ArrayList by their index.
True (*)
False
Correct
(1/1) Points
3. Which of the following is not a wrapper class?
Boolean
String (*)
Byte
Integer
Correct
(1/1) Points
4. Arrays are like variables which must be declared prior to use.
True (*)
False
Correct
(1/1) Points
5. Given:
int x[];
What is the value of x?

1
Some random number.
null (*)
0
Correct
6. 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]);
}
01234 (*)
123
12345
012345
Correct
(1/1) Points
7. The Java compiler does not check for an ArrayIndexOutOfBoundsException
during the compilation of a program containing arrays.
True (*)
False
Correct
(1/1) Points
8. What is the starting index of an array?
It depends on the type of the array.
1
0 (*)
You can start with anything
Correct
(1/1) Points
9. What is the output?
int[] arr = new int[1];
arr[0] = 10;
System.out.println(arr[0]);

0
ArrayIndexOutOfBoundsException
1
10 (*)
Correct
(1/1) Points
10. Testing and debugging are important activities in software development.
True (*)
False
Correct
11. Runtime errors can be caught by Java’s exception handling mechanism.
True (*)
False
Correct
(1/1) Points
12. Identify where there is a potential bug in this code:

int radiusOfCircle = 10;


int areaOfCircle = Math.PI * radiusOfCircle * radiusOfCircle;
A semi-colon is missing.
A datatype is incorrect. (*)
A variable name is misspelled.
A variable hasn’t been assigned a value.
Correct
(1/1) Points
13. 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
(1/1) Points
14. Which exception is thrown when an application attempts to use null when
an object is required?
NullPointerException (*)
FileNotFoundException
ArithmeticException
ArrayIndexOutOfBoundsException
Correct
(1/1) Points
15. What is the danger of catching a generic Exception type as shown below?

int[] array = {10, 20, 30};


int b = 0;
try{
System.out.println("1");
int c = (array[3] / b);
System.out.println("2");
}
catch(Exception ex){
System.out.println(ex.toString());
}
The details of the Exception object ex are too general to be useful. (*)
An Exception will never occur.
An ArithmeticException cannot be caught.
An ArrayIndexOutOfBoundsException cannot be caught.
Correct

You might also like