Specifications

Sun Services
Java™ Programming Language
Module 7, slide 32 of 44
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
The Solution
The declaration of the Vehicle class is:
1 public abstract class Vehicle {
2 public abstract double calcFuelEfficiency();
3 public abstract double calcTripDistance();
4}
The Truck class must create an implementation:
1 public class Truck extends Vehicle {
2 public Truck(double maxLoad) {...}
3 public double calcFuelEfficiency() {
4 /* calculate the fuel consumption of a truck at a given load */
5 }
6 public double calcTripDistance() {
7 /* calculate the distance of this trip on highway */
8 }
9}