Classes and Objects

Learn about classes and member variables in object-oriented programming.

We'll cover the following...

Classes and objects

In object-oriented programming, a class is like a blueprint, or description, of something. Let’s take the concept of a person as an example. How can we describe a person? We can start to make a list of things that apply to all people. A person has the following attributes:

  • Name
  • Age
  • Sex
  • Height
  • Weight
  • Hair color
  • Eye color
  • Shoe size
  • Nationality
  • Address
  • Telephone number

The list can go on. We can now decide that these are things that apply to all people. If we think about it, this is all data about a person. We haven’t described any behavior. We could make another list that describes things a person can do. A person can do the following:

  • Jump
  • Run
  • Walk
  • Sit
  • Stand
  • Sleep
  • Chill
  • Work
  • Play
  • Dance

The same thing applies here—the list can be very long.

If we’re going to represent a person in a program, we won’t need all the available data and behavior. Instead, we need to make an abstract of a person in such a way that we can represent them with the things that ...