exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 63 discussion

Actual exam question from Oracle's 1z0-809
Question #: 63
Topic #: 1
[All 1z0-809 Questions]

Given:
class FuelNotAvailException extends Exception { }
class Vehicle {
void ride() throws FuelNotAvailException { //line n1
System.out.println("Happy Journey!");
}
}
class SolarVehicle extends Vehicle {
public void ride () throws Exception { //line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws FuelNotAvailException, Exception {
Vehicle v = new SolarVehicle ();
v.ride();
}
Which modification enables the code fragment to print Happy Journey!?

  • A. Replace line n1 with public void ride() throws FuelNotAvailException {
  • B. Replace line n1 with protected void ride() throws Exception {
  • C. Replace line n2 with void ride() throws Exception {
  • D. Replace line n2 with private void ride() throws FuelNotAvailException {
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Tarik2190
Highly Voted 3 years, 3 months ago
According to overriding rules, if super class / interface method declares to throw a checked exception, then overriding method of sub class / implementer class has following options: 1. May not declare to throw any checked exception. 2. May declare to throw the same checked exception thrown by super class / interface method. 3. May declare to throw the sub class of the exception thrown by super class / interface method. 4. Cannot declare to throw the super class of the exception thrown by super class / interface method. 5. Cannot declare to throw unrelated checked exception. 6. May declare to throw any RuntimeException or Error.
upvoted 8 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 3 weeks ago
B is the Correct answer
upvoted 1 times
...
steefaand
5 months, 3 weeks ago
Selected Answer: B
B is correct since base method can't declare narrower Exception type than overridden method.
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is B.
upvoted 1 times
...
Tarik2190
3 years, 3 months ago
Answer is B, tested
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago