September 2011
Beginner
650 pages
15h 47m
English
As you learned in Chapter 6, often an instance variable of a class will be declared private to prevent its unauthorized use or tampering. Inheriting a class does not overrule the private access restriction. Thus, even though a subclass includes all of the members of its superclass, it cannot access those members of the superclass that have been declared private. For example, if, as shown here, width and height are made private in TwoDShape, then Triangle will not be able to access them:

The Triangle class will not compile because the reference to width and height inside the area( ) method causes an access violation. ...
Read now
Unlock full access