The Anatomy of a Class
Class Members:
Methods
Methods define what an object can do or the behavior of the object.
Constructors
Constructors don’t actually construct the object. The class makes the object and then executes a constructor to initialize the values of the fields (instance variables).
Member Access Specifiers
The members of a class are classified into three categories: private, public, and protected. This chapter mainly discusses the first two types, private and public. In C++, private, protected, and public are reserved words and are called member access specifiers.
Following are some facts about public and private members of a class:
By default, all members of a class are private.
If a member of a class is private, you cannot access it directly from outside of the class.
A public member is accessible outside of the class.
To make a member of a class public, you use the member access specifier public with a colon, :
Object Diagram
Encapsulation
There are two views of an object:
internal - the details of the variables and methods of the class that defines it
external - the services that an object provides and how the object interacts with the rest of the system
From the external view, an object is an encapsulated entity, providing a set of specific services
These services define the interface to the object
COSC-1336 / ITSE-1302 Computer Science - Author: Dr. Kevin Roark