Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 1

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?

    Correct Answer: D

    The code will result in a compilation error at line n3. The method speed() is being called without an instance of the nested class Car. To call the speed() method correctly, you need to create an instance of the Car class and then call the method using that instance. Therefore, the correct code would be new Car().speed() at line n3. As it stands, the call to speed() at line n3 is incorrect and will cause a compilation error.

Discussion
HanenBAOption: 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

JonanienOption: D

D, function call without object reference

MinksOption: D

The correct answer is D. The code fails at line 3. Tested

maslacOption: A

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); } }

varconiteOption: D

answer is D

r1muka5Option: D

The correct answer is D.

mrjavaOption: D

The method speed is not visable for the method , you must to create Object referance from inner class

Kyle_XYOption: D

The answer is D

YasinGaberOption: D

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.

Svetleto13Option: A

A,tested

Svetleto13

If we test it with new.Car().speed() answer is A, and just how it is is answer is D.

meyowOption: D

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

asdfjhfgjuaDCVOption: D

D is the answer.

steefaandOption: D

Answer is D since speed method requires object of Car class.

vleuntiOption: D

Answer D

sandoro

Actually I was confused because at the top we have Class Vehicle with capital letter instead of class Vehicle

MilkBiscuitOption: D

There are 2 'line 3' and increSpeed doesn't even have the close bracket.