Rectangle
class includes
TwoDShape
and adds the methods
IsSquare( )
, which
determines if the rectangle is square, and
Area( )
, which computes the area of a rectangle.
Member Access and Inheritance
As explained in Chapter 8, members of a class are often declared private to prevent their
unauthorized use or tampering. Inheriting a class
does not
overrule the private access
restriction. Thus, even though a derived class includes all of the members of its base class,
it cannot access those members of the base class that are private. For example, if, as shown
here,
Width
and
Height
are made private in
TwoDShape
, then
Triangle
will not be able to
access them:
// Access to private members is not inherited.
// This example will not compile.
using System;
// A class for two-dimensional objects.
class TwoDShape {
www.freepdf-books.com
Do'stlaringiz bilan baham: |