Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Consider the following code snippet: public class Vehicle { . . . public void

ID: 3691126 • Letter: 1

Question

1. Consider the following code snippet:
public class Vehicle

{

   . . .

   public void setVehicleClass(double numberAxles)

   {

     . . .

    }

}

public class Motorcycle extends Vehicle

{

. . .

   public void setVehicleClass(double numberAxles)

   {

     . . .

    }

}

Which of the following statements is correct?

a. The Motorcycle class overrides the setVehicleClass method.

b. The Vehicle class overrides the setVehicleClass method.

c. The Motorcycle class overloads the setVehicleClass method.

d. The Vehicle class overloads the setVehicleClass method.

2. Consider the following code snippet:

public class Inventory implements Measurable

{

private int onHandCount;

. . .

public double getMeasure();

   {

     return onHandCount;

   }

}

Why is it necessary to declare getMeasure as public?

a. All methods in a class are not public by default.

b. All methods in an interface are private by default.

c. It is necessary only to allow other classes to use this method.

d. It is not necessary to declare this method as public.

3. Consider the following code snippet:

public class Motorcycle extends Vehicle

{

. . .

public Motorcycle(int numberAxles)

{

     super.numberAxles;

   }

}

What does this code do?

a. It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.

b. It invokes the constructor of the Motorcycle class from within the constructor of the Vehicle class.

c. It invokes a private method of the Vehicle class from within a method of the Motorcycle class.

d. This code will not compile.

4. To create a subclass, use the ____ keyword.

a. inherits.

b. implements.

c. interface.

d. extends.

5. Which of the following statements about an interface is true?

a. An interface has methods and instance variables.

b. An interface has methods but no instance variables.

c. An interface has neither methods nor instance variables.

d. An interface has instance variables but no methods.

Explanation / Answer

1) a

2) c

3) a

4) d

5) a