Method

A Method is a Function / procedure inside a class.

Any method can be seen as either an accessor or a mutator

  • An accessor reports on the “value” of the object, but doesn’t change it; a true accessor can be declared as const
  • A mutator may change the “value” of the object; it cannot be declared as const

When multiple objects of the same class is created, are the methods duplicated?

NO! All objects of the same class share a single copy of the methods.

Check out this downvoted StackOverflow question.

But these methods access member variables, which differ between objects. How does that work?

When a method is called on an object, it has access to that object’s specific member variables through the hidden this parameter (ahhh). This is how we can work with the correct instance data for each object.

Are the member fields duplicated a million times? Yes, see Virtual Method.