PART I
C h a p t e r 1 1 :
I n h e r i t a n c e
273
PART IPART I
double Width; // now private
double Height; // now private
public void ShowDim() {
Console.WriteLine("Width and height are " +
Width + " and " + Height);
}
}
// Triangle is derived from TwoDShape.
class Triangle : TwoDShape {
public string Style; // style of triangle
// Return area of triangle.
public double Area() {
return Width * Height / 2; // Error, can't access private member
}
// Display a triangle's style.
public void ShowStyle() {
Console.WriteLine("Triangle is " + Style);
}
}
The
Triangle
class will not compile because the use of
Do'stlaringiz bilan baham: |