Objects with a Class Scope

Encapsulation usually takes place at the class level. The class is designed as a template of methods and variables. The instances themselves retain only the values of their object variables (attributes).

Within the hierarchy, the class structure ensures the integrity of a class's object variables (attributes), controlling the methods allowed to operate on them. The class structure also provides for easy updating of the method code. If a method requires a change, you only have to change it once, at the class level. The change then is acquired by all the instances sharing the method.

Associated methods and variables have a certain scope, which is the class to which they belong:


Scope of the Number Class

Each class in a class hierarchy has a scope different from any other class. This is what allows an object variable (attribute) in a subclass to have the same name as an object variable (attribute) in a superclass, even though the methods that use the object variables (attributes) for completely unrelated purposes.