Java Reference
In-Depth Information
The Rectangle class includes TwoDShape and adds the methods isSquare( ) , which de-
termines if the rectangle is square, and area( ) , which computes the area of a rectangle.
Member Access and Inheritance
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 super-
class, 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:
Search WWH ::




Custom Search