A class declaration defines a new type that links code and data. This new type is then used to declare objects of that class. Thus, a class is a logical abstraction, but an object has physical existence. In other words, an object is an instance of a class.
By default, functions and data declared within a class are private to that class and may be accessed only by other members of the class. The public access specifier allows functions or data to be accessible to other parts of your program. The protected access specifier is needed only when inheritance is involved (see Chapter 15). Once an access specifier has been used, it remains in effect until either another access specifier is encountered or the end of the class declaration is reached.
You may change access specifications as often as you like within a class declaration. For example, you may switch to public for some declarations and then switch back to private again. The class declaration in the following example illustrates this feature:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.