Classes: Creating classes

Introduction to Classes: Terms

  • Object: combines data(attributes, properties, variables) and member functions(methods).
  • Encapsulation: combining data and code into a single object
  • Data hiding: making attributes (variables) private and controlling access to them with methods (functions)
  • Class: code that specifies the attributes *variables) and member functions (methods)
  • Instance: An object created from the class.
  • Private: (access specifier) Private attributes and methods can only be used inside the class definition.
  • Public: (access specifier) Public attributes and methods are ones that can be accessed outside the class definition.
  • Accessors: Accessors retrieve values from the class, usually named get___, also called getter functions
  • Mutators: Mutators change the values in the class, usually named get___, also called setter functions.
  • Constructor: Method with same name as class, used to give initial values to the attributes.
  • Destructor: Member function with same name as the class with a ~ in front. The destructor is called when the object is destroyed.
  • Overloaded constructors: Constructors can be written with different arguments. Usually there is one constructor with no arguments (the default constructor) and ones with different attributes given values.

Please study the material at each of the links below.

  1. A rectangle class
  2. Expanding on the rectangle class
  3. More methods for rectangle class
Like us on Facebook:


OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher: Zebra0.com
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 18 2017 13:59:57.