exam questions

Exam 1z0-809 All Questions

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

Exam 1z0-809 topic 1 question 1 discussion

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

Given the definition of the Vehicle class:
Class Vehicle {
int distance;
Vehicle (int x) {
this distance = x;
}
public void increSpeed(int time) {
int timeTravel = time; //line n1
//line n3
class Car {
int value = 0;
public void speed () {
value = distance /timeTravel; //line n2
System.out.println ("Velocity with new speed"+value+"kmph");
}
}
speed(); //line n3
}
}
and this code fragment:
Vehicle v = new Vehicle (100);
v.increSpeed(60);
What is the result?

  • A. Velocity with new speed 1 kmph
  • B. A compilation error occurs at line n1.
  • C. A compilation error occurs at line n2.
  • D. A compilation error occurs at line n3.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

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
asdfjhfgjuaDCV
5 months ago
D is the answer.
upvoted 1 times
...
steefaand
5 months, 4 weeks ago
Selected Answer: D
Answer is D since speed method requires object of Car class.
upvoted 1 times
...
vleunti
9 months, 3 weeks ago
Selected Answer: D
Answer D
upvoted 1 times
...
sandoro
1 year ago
Actually I was confused because at the top we have Class Vehicle with capital letter instead of class Vehicle
upvoted 1 times
...
r1muka5
1 year, 5 months ago
The correct answer is D.
upvoted 2 times
...
MR_JAVA
1 year, 5 months ago
Selected Answer: D
The method speed is not visable for the method , you must to create Object referance from inner class
upvoted 2 times
...
Jonanien
1 year, 9 months ago
Selected Answer: D
D, function call without object reference
upvoted 3 times
...
Kyle_XY
2 years, 3 months ago
The answer is D
upvoted 2 times
...
HanenBA
2 years, 5 months ago
Selected Answer: D
the call to the method speed() is out of the class Car, so the call must be with new Car().speed() to be correct
upvoted 4 times
...
YasinGaber
2 years, 5 months ago
Compiling the code we get compilation error at line 3 speed() it should be new Car().speed() Hence, the correct answer is D, but if we get this question in real exam, should we follow the answer given here and answer it as A or we should go by answer D? really confusing.
upvoted 2 times
...
Minks
2 years, 10 months ago
The correct answer is D. The code fails at line 3. Tested
upvoted 3 times
...
Svetleto13
3 years, 2 months ago
A,tested
upvoted 2 times
Svetleto13
3 years, 2 months ago
If we test it with new.Car().speed() answer is A, and just how it is is answer is D.
upvoted 4 times
...
...
meyow
3 years, 3 months ago
it can be like that package exam_topics.q01; public class Vehicle { int distance; Vehicle(int x) { this.distance = x; } public void increSpeed(int time) { int timeTravel = time; //line n1 class Car { int value = 0; public void speed() { value = distance / timeTravel; //line n2 System.out.println("Velocity with new speed" + value + "kmph"); } } Car car=new Car(); car.speed(); } public static void main(String[] args) { Vehicle v = new Vehicle(100); v.increSpeed(60); } } answer D
upvoted 2 times
...
maslac
3 years, 4 months ago
correct answer is A, tested class Vehicle { int distance; Vehicle (int x) { this.distance = x; } public void increSpeed(int time) { int timeTravel = time; //line n1 class Car { int value = 0; public void speed () { value = distance / timeTravel; //line n2 System.out.println ("Velocity with new speed " + value + " kmph"); } } new Car().speed(); //line n3 } public static void main(String[] args) { Vehicle v = new Vehicle (100); v.increSpeed(60); } }
upvoted 3 times
...
MilkBiscuit
3 years, 7 months ago
There are 2 'line 3' and increSpeed doesn't even have the close bracket.
upvoted 1 times
...
varconite
3 years, 8 months ago
answer is D
upvoted 3 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