Fields

This lesson will go into the details of the member variables or fields of a class.

Fields #

As discussed earlier, fields are actually the member variables inside a class. For instance, in a class representing a vending machine, the VendingMachine class might contain the following fields:

  • A count of type int that stores the count of products available in the machine.
  • A capacity of type int that stores the maximum number of products the machine can have.
  • A moneyCollected of type int to store the money it has collected.
  • A manufacturer of type string to store the name of the manufacturer of the machine.

Get hands-on with 1200+ tech skills courses.