Classes and Objects
Fields, methods, constructors and static members, and the Java versus C++ difference in what "b = a" means for an object.
Class versus object
A class is a blueprint: it lists what data something holds and what it can do. An object (also called an instance) is one thing built from that blueprint, with its own copy of the data.
- Field (data member): a variable that belongs to an object, such as
balance. - Method (member function in C++): a function that works on an object's fields.
- Constructor: special method that runs when the object is created and sets it up.
this: the object a method is currently running on.
In UML (a standard diagram notation, covered later), - means private, + means public and $ means static.
1 of 6