Oracle 1z0-803 Exam Practice Questions (P. 2)
- Full Access (216 questions)
- Six months of Premium Access
- Access to one million comments
- Seamless ChatGPT Integration
- Ability to download PDF files
- Anki Flashcard files for revision
- No Captcha & No AdSense
- Advanced Exam Configuration
Question #6
An unchecked exception occurs in a method dosomething()
Should other code be added in the dosomething() method for it to compile and execute?
Should other code be added in the dosomething() method for it to compile and execute?
- AThe Exception must be caught
- BThe Exception must be declared to be thrown.
- CThe Exception must be caught or declared to be thrown.
- DNo other code needs to be added.
Correct Answer:
D
Because the Java programming language does not require methods to catch or to specify unchecked exceptions (RuntimeException, Error, and their subclasses), programmers may be tempted to write code that throws only unchecked exceptions or to make all their exception subclasses inherit from RuntimeException. Both of these shortcuts allow programmers to write code without bothering with compiler errors and without bothering to specify or to catch any exceptions. Although this may seem convenient to the programmer, it sidesteps the intent of the catch or specify requirement and can cause problems for others using your classes.
D
Because the Java programming language does not require methods to catch or to specify unchecked exceptions (RuntimeException, Error, and their subclasses), programmers may be tempted to write code that throws only unchecked exceptions or to make all their exception subclasses inherit from RuntimeException. Both of these shortcuts allow programmers to write code without bothering with compiler errors and without bothering to specify or to catch any exceptions. Although this may seem convenient to the programmer, it sidesteps the intent of the catch or specify requirement and can cause problems for others using your classes.
send
light_mode
delete
Question #7
Given the code fragment:

What is the result?

What is the result?
- A2
- B1
- C3
- D3
Correct Answer:
A
Variable b is set to 4.
Variable b is decreased to 3.
Variable b is decreased to 2 and then printed. Output: 2
Variable b is printed. Output: 2
A
Variable b is set to 4.
Variable b is decreased to 3.
Variable b is decreased to 2 and then printed. Output: 2
Variable b is printed. Output: 2
send
light_mode
delete
Question #8
Given the code fragment:
interface SampleClosable {
public void close () throws java.io.IOException;
}
Which three implementations are valid?

interface SampleClosable {
public void close () throws java.io.IOException;
}
Which three implementations are valid?

- AOption A
- BOption B
- COption C
- DOption D
- EOption E
Correct Answer:
ACE
A: Throwing the same exception is fine.
C: Using a subclass of java.io.IOException (here java.io.FileNotFoundException) is fine
E: Not using a throw clause is fine.
Incorrect answers:
B: Exception is not a subclass of java.io.IOException and cannot be used here.
D: Not extends. SampleCloseable cannot be the superclass of Test, a superclass must be a class. (An interface extends other interfaces.)
ACE
A: Throwing the same exception is fine.
C: Using a subclass of java.io.IOException (here java.io.FileNotFoundException) is fine
E: Not using a throw clause is fine.
Incorrect answers:
B: Exception is not a subclass of java.io.IOException and cannot be used here.
D: Not extends. SampleCloseable cannot be the superclass of Test, a superclass must be a class. (An interface extends other interfaces.)
send
light_mode
delete
Question #9
Given the code fragment:

What is the result?

What is the result?
- A4 Null
- BNull
- CAn IllegalArgumentException is thrown at run time
- D4
Correct Answer:
D
The first println statement, System.out.println(array [4][1]);, works fine. It selects the element/array with index 4, {0, 4, 8, 12, 16}, and from this array it selects the element with index 1, 4. Output: 4
The second println statement, System.out.println(array) [1][4]);, fails. It selects the array/element with index 1, {0, 1}, and from this array it try to select the element with index 4. This causes an exception.
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
D
The first println statement, System.out.println(array [4][1]);, works fine. It selects the element/array with index 4, {0, 4, 8, 12, 16}, and from this array it selects the element with index 1, 4. Output: 4
The second println statement, System.out.println(array) [1][4]);, fails. It selects the array/element with index 1, {0, 1}, and from this array it try to select the element with index 4. This causes an exception.
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
send
light_mode
delete
Question #10
Given:

How many times is 2 printed as a part of the output?

How many times is 2 printed as a part of the output?
send
light_mode
delete
All Pages