Log in

View Full Version : Are my answers right? Java


Chrissy00
Dec 11, 2012, 08:38 AM
Use the following class definitions to answer questions 4 through 7

public class Vehicle
{
private int passengers;
private int fuelcap;
private int mpg;
Vehicle(int p, int f, int m)
{
passengers = p;
fuelcap = f;
mpg = m;
}
}
public class Truck extends Vehicle
{
private int cargocap;
private int test;
Truck(int p, int f, int m, int c)
{
super(p,f,m);
cargocap = c;
}
}
public class TruckDemo
{
public static void main(String[] args)
{
Truck semi = new Truck(2,200,7,44000);
Truck pickup = new Truck(3,28,15,2000);
}
}

4. Class Vehicle shown above contains this definition of an attribute: private int passengers. According to the rules of Java, I can directly access Class Vehicles passengers attribute from Class TruckDemo by using Vehicle.passengersTRUE FALSE

5. In the example above, Class Vehicle is the parent (or base) class, while class Truck is the child (or derived) class.
TRUE FALSE

6. The main method in the TruckDemo class instantiates two identical objects of the Truck class.
TRUE FALSE

7. The Truck class may include a static method.
TRUE FALSE