Program 7.3: A Motorcycle Class

Now suppose you also need a class for a motorcycle. A motorcycle also has a make, a model, a year, a maximum speed, a weight, a price, a number of passengers it can carry, two wheels and many other properties you can represent with member variables. A class that represents a motorcycle might look like this:

class Motorcycle {

  String make;
  String model;
  int year;
  int max_speed;
  int weight
  float price;
  int num_passengers;
  int num_wheels = 2;

}

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home