exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 213 discussion

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

Given these requirements:
✑ Bus and Boat are Vehicle type classes.
✑ The start() and stop() methods perform common operations across the Vehicle class type.
✑ The ride() method performs a unique operations for each type of Vehicle.
Which set of actions meets the requirements with optimized code?

  • A. 1. Create an abstract class Vehicle by defining start() and stop() methods, and declaring the ride() abstract method. 2. Create Bus and Boat classes by inheriting the Vehicle class and overriding the ride() method.
  • B. 1. Create an interface Vehicle by defining start() and stop() methods, and declaring the ride() abstract method. 2. Create Bus and Boat classes by implementing the Vehicle class.
  • C. 1. Create an abstract class Vehicle by declaring stop(), start(), and ride() abstract methods. 2. Create Bus and Boat classes by inheriting the Vehicle class and overriding all the methods.
  • D. 1. Create an interface Vehicle by defining default stop(), start(), and ride() methods. 2. Create Bus and Boat classes by implementing the Vehicle interface and overriding the ride() method.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
MPignaProTech
2 months, 2 weeks ago
Selected Answer: A
A is the good answer
upvoted 1 times
...
Syyyyyyyy
10 months, 1 week ago
Selected Answer: A
Apparently it's A. Both A and D can work, but default methods in interfaces are introduced to provide extension to interfaces, not really to use it to provide abstraction.
upvoted 2 times
...
charbelishak
12 months ago
Selected Answer: A
both A and D are correct. in A, we define an abstract class with concrete methods for start() and stop(), and an abstract ride(). in B, we define default start() and stop(), and ride() we keep it abstract. meaning in both approaches we are defining a common operation, and require an overridden version for ride() for the code to work. the only difference is if we want to extend another class other than Vehicle, then we need option D, however with the requirements we have here, both options works fine.
upvoted 2 times
...
kingofkotha
1 year, 1 month ago
option A is right answer.
upvoted 2 times
...
Ericausdresden
1 year, 5 months ago
But why is it not Answer A, though?
upvoted 4 times
...
yyfabc
1 year, 8 months ago
It feels weird to me ... if i have to solve this problem in a realistic scenario, i think i could create abstract class with implementations of those 2 methods and make ride() abstract, or using default in interface to put fixed logic for the 2 methods and let Bus and Boat implement the interface and override ride().. plz correct me for any mistake, tx!
upvoted 1 times
...
UAK94
2 years, 2 months ago
interface Vehicle{ default void start() {} default void stop() {} default void ride() {} } class Bus implements Vehicle{ public void ride() {System.out.println("Bus");} } public class Boat implements Vehicle{ public void ride() {System.out.println("Boat");} } Answer is D
upvoted 2 times
...
iSnover
2 years, 3 months ago
Selected Answer: D
The answer is the letter D, the question makes it clear that the "start()", "stop()" and "ride()" methods all classes need to have, so Vehicle needs to be an interface to be optimized, with that we eliminate alternative A and C. The letter B is also correct but it is not as optimized as D, because all the methods of an interface are by default public and abstract, you don't need to declare this when instantiating the method, you just need to overload it.
upvoted 2 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