previous | index | next

Defining Classes

Consider a simplified version of the Item class from the online clothing application:

The reason for changing the class name to ItemInfo will be given later.

A class definition encapsulates a class's methods and instance variables.

Here is a class definition for the ItemInfo class:

class ItemInfo {
  // Here are the methods:
  double getPrice() { return price; }
  string getColor() { return color; }

  // Here are the instance variables:
  double price;
  string color;
};  // note the semicolon!


previous | index | next