Difficulty: Introductory | Prerequisites: C++ functions, variables, and basic program structure (Chapters 1–6).
This is your first real encounter with object-oriented programming in C++. Chapter 7 introduces the idea that data and the functions operating on that data can live together inside a single unit called a class. Everything here underpins later work with inheritance, polymorphism, and larger program design. If you are comfortable writing functions and using structs informally, you are ready for this.
C++ lets you bundle related data and the functions that work on that data into a single unit called a class. Each class acts as a blueprint; the actual working copies you create from it are called objects (or instances). Access specifiers (private and public) control who can touch what, and special functions called constructors and destructors handle setup and teardown automatically.
Abstract Data Type (ADT)
A programmer-defined data type that specifies the values it can hold and the operations that can be performed on them, while hiding the implementation details. In simple terms, it is a contract: "here is what you can do with this data" without revealing how it is done internally. In C++, ADTs are normally implemented as classes. Note: ADT stands for Abstract Data Type, not Algorithmic Data Type.
Class
A user-defined data type that serves as a blueprint for creating objects. It declares the member variables (data) and member functions (behaviour) that its objects will have. A class declaration alone does not create any objects.
Object
A working instance of a class. When you declare a variable of a class type, you create an object. Each object gets its own copy of the class's member variables.
Instance
Another word for object. When three objects of the same class exist, they are three separate instances of that class.
Encapsulation
The bundling of an object's data and its functions into one unit. Think of it as putting everything related to one concept inside a single container so it travels and behaves as a whole.
Data hiding
The practice of restricting direct access to an object's internal data. Closely related to encapsulation, but specifically about keeping the data behind a controlled interface.
Access specifier
A keyword (public or private) that controls which parts of a class can be reached from outside. The private access specifier protects important data from direct external access.
Public member
A member variable or function that can be accessed from code outside the class, using the dot operator on an object.
Private member
A member variable or function that can only be accessed from within the class's own member functions. Private member functions may only be called from a function that is a member of the same class.
Member variable (attribute)
A variable declared inside a class. In OOP terminology, member variables are often called attributes.
Member function (method)
A function declared inside a class. In OOP terminology, member functions are sometimes referred to as methods.
Accessor (getter)
A member function that reads and returns the value of a member variable without changing it. Accessors are sometimes called "get" functions.
Mutator (setter)
A member function that changes or sets the value stored in a member variable. Mutators are sometimes called "set" functions.
Dot operator (.)
The operator used to access public members of an object from outside the class. For example, myCircle.setRadius(2.5); calls the setRadius function on the myCircle object.
Inline function
A member function whose body is defined directly inside the class declaration, rather than separately outside it.
Scope resolution operator (::)
Used to qualify a member function's name with its class name when defining that function outside the class declaration. Written as ClassName::functionName.
OOP is centred around objects that include both data and the functions that operate on that data.
The core idea: instead of scattering related variables and functions across a program, you group them into self-contained units.
ADTs specify what values a type can hold, what operations it supports, and hide the implementation details. All three of these are true, not just the first two.
A class declaration is a blueprint. It provides a pattern for creating objects but does not itself create any objects.
To create an object, you declare a variable of the class type: Circle myCircle; creates a Circle object named myCircle.
The syntax is ClassName objectName; with no parentheses. Writing Circle myCircle(); does not create an object (the compiler reads it as a function declaration).
When multiple objects of a class are created, they are separate instances of that class, each with its own copy of the member variables.
private: members declared here can only be accessed by the class's own member functions. This is the mechanism that protects important data.
public: members declared here can be accessed from outside the class using the dot operator on an object.
An object typically hides its data (keeps member variables private) and allows outside code to reach it through public member functions.
Accessors read a member variable's value without changing it. Also called "get" functions.
Mutators change or set a member variable's value. Also called "set" functions.
Accessors are sometimes called get functions and mutators are sometimes called set functions (the order matters for exam questions: get/set, not set/get).
An inline function has its body defined directly inside the class declaration.
A member function defined outside the class must be qualified with the class name and the scope resolution operator: void Circle::setRadius(double r) { ... }
You call a member function on a specific object using the dot operator: myCircle.setRadius(2.5);
You cannot call the function on its own (setRadius(2.5); is wrong) or on the class name (Circle.setRadius(2.5); is wrong).
The function must be called on the object that owns the data you want to affect.
A public member function may be called by any code outside the class.
A private member function may only be called from within the class's own member functions.
This distinction appears frequently in exam questions.
Students often think a class declaration creates an object. It does not. A class is only a blueprint; you must declare a variable of that type to get an actual object.
Students often confuse "encapsulation" with "data hiding." Encapsulation is the bundling of data and functions together. Data hiding is the restriction of access to that data. They are related but not the same concept.
Students often assume ADT stands for "Algorithmic Data Type." It stands for Abstract Data Type. This is a common trick question.
Students sometimes write Circle myCircle(); expecting to create an object. In C++ this is parsed as a function declaration, not an object creation. The correct form is Circle myCircle; with no parentheses.
Students sometimes call a member function without an object, writing setRadius(2.5); instead of myCircle.setRadius(2.5);. The dot operator and the object name are required.
⚠️ The difference between a class and an object appears in almost every version of the test. A class is a blueprint; an object is an instance of that class.
⚠️ Know the correct syntax for creating an object: ClassName objectName; (no parentheses, no equals sign).
⚠️ Know the correct syntax for calling a member function: objectName.functionName(args); (not ClassName.functionName() or functionName() alone).
⚠️ Accessors = get functions, mutators = set functions. The pairing order is tested directly.
⚠️ ADT stands for Abstract Data Type. ADTs specify values, operations, and hide implementation. All three.
⚠️ The private access specifier is used to protect important data. Public member functions provide the controlled interface.
⚠️ Member variables are called attributes; member functions are called methods. This specific pairing is tested.
⚠️ A function body defined inside the class declaration makes it an inline function.
True or False: A class declaration creates an object. (Answer: False)
ADT stands for ________ Data Type. (Answer: Abstract)
True or False: Encapsulation and data hiding are exactly the same thing. (Answer: False)
An object's member variables are called its ________, and its member functions are called its ________. (Answer: attributes, methods)
True or False: A private member function can be called from code outside the class. (Answer: False)
Q: Which of the following statements about ADTs is true? (a) They specify the values the data type can hold. (b) They specify the operations the data type can perform. (c) They hide how the data type is implemented. (d) All of the above.
A: (d) All of the above. ADTs do all three.
Q: What is the correct way to create an object of class Square named box?
A: Square box; No parentheses, no equals sign. The class name comes first, then the object name.
Q: If setSide is a member function of class Square and box is a Square object, which statement sets the side to 5?
A: box.setSide(5); You must use the dot operator on the specific object.
Q: What is the difference between an accessor and a mutator?
A: An accessor (getter) reads a member variable's value without changing it. A mutator (setter) changes or sets a member variable's value.
Q: The bundling of an object's data and functions together is called what?
A: Encapsulation.
Q: What mechanism is used to protect important data inside a class?
A: The private access specifier.
Q: When a member function body is defined inside the class declaration, it is called what kind of function?
A: An inline function.
Q: When a member function is defined outside the class declaration, the function name must be qualified with the class name followed by what?
A: The scope resolution operator (::).
This material connects directly to constructors, destructors, structures, and enumerated types (covered in Part 2 of these notes), which round out the Chapter 7 exam content. It also sets the foundation for Chapter 11 on inheritance and Chapter 15 on polymorphism, where classes become the building blocks for larger hierarchies. If you are comfortable with how access specifiers and member functions work here, the jump to derived classes later will feel much more manageable.
C++ classes, C++ objects, object-oriented programming, OOP C++, CS101, abstract data type, ADT, encapsulation, data hiding, access specifier, public private C++, member variable, member function, attribute, method, accessor, mutator, getter, setter, dot operator, inline function, scope resolution operator, Gaddis Chapter 7, Starting Out with C++ Early Objects, class declaration, instance, class blueprint, object creation syntax