hiexam
oracle · 1z0-809 · Q604 · multiple_choice · topic_1

Given the definition of the Vehicle class: Class Vehicle { int distance; Vehicle (int x) { this distance = x; } public…

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.
Explanation
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

Reference: examtopics_top_comment

Practice with progress tracking

Sign in to track wrong answers, get spaced-repetition reminders, and run timed exam mode.