Answer:
- the notation while(!found) { ... } is semantically very clear
- you can initialize the found boolean as false
Explanation:
Within the while loop you will assign the compound condition to the 'found' variable. By initializing the variable with 'false' you ensure that the values used in the compound condition are valid.
Simplified example: read user input until 'Y' is pressed:
found = false;
while(!found) {
userInput = readUserInput();
found = (userInput == 'Y');
}
Answer:
The answer is D.
Explanation:
The question is incomplete, here is the full question;
Insert the missing code in the following code fragment. This fragment is intended to call the Vehicle class's method.
public class Vehicle
{
. . .
public void setVehicleClass(double numberAxles)
{
. . .
}
}
public class Motorcycle extends Vehicle
{
. . .
public Motorcycle()
{
_______________;
}
}
a) Motorcyle.setVehicleClass(2.0);
b) Vehicle.setVehicleClass(2.0);
c) this.setVehicleClass(2.0);
d) setVehicleClass(2.0);
According to the information and the code snippet given in the question, the correct answer to fill in the blank should be D, setVehicleClass(2.0); because it is in the Motorcycle class which "extends" vehicle meaning that it's a subclass.
I hope this answer helps.
Comment should always be answered in the prospective language the question is asked.