30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

372 Object-Oriented <strong>Program</strong>ming: Inheritance Chapter 9<br />

14 ' get CCircle4's initial x-y coordinates and radius<br />

15 output = "X coordinate is " & circle.X & vbCrLf & _<br />

16 "Y coordinate is " & circle.Y & vbCrLf & "Radius is " & _<br />

17 circle.Radius<br />

18<br />

19 ' set CCircle4's x-y coordinates and radius <strong>to</strong> new values<br />

20 circle.X = 2<br />

21 circle.Y = 2<br />

22 circle.Radius = 4.25<br />

23<br />

24 ' display CCircle4's String representation<br />

25 output &= vbCrLf & vbCrLf & _<br />

26 "The new location and radius of circle are " & _<br />

27 vbCrLf & circle.ToString() & vbCrLf<br />

28<br />

29 ' display CCircle4's diameter<br />

30 output &= "Diameter is " & _<br />

31 String.Format("{0:F}", circle.Diameter()) & vbCrLf<br />

32<br />

33 ' display CCircle4's circumference<br />

34 output &= "Circumference is " & _<br />

35 String.Format("{0:F}", circle.Circumference()) & vbCrLf<br />

36<br />

37 ' display CCircle4's area<br />

38 output &= "Area is " & String.Format("{0:F}", circle.Area())<br />

39<br />

40 MessageBox.Show(output, "Demonstrating Class CCircle4")<br />

41 End Sub ' Main<br />

42<br />

43 End Module ' modCircleTest4<br />

Fig. 9.13 modCircleTest4 demonstrates class CCircle4 functionality<br />

(part 2 of 2).<br />

9.5 Case Study: Three-Level Inheritance Hierarchy<br />

Let us consider a substantial inheritance example, in which we study a point-circle-cylinder<br />

hierarchy. In Section 9.4, we developed classes CPoint (Fig. 9.4) and CCircle4<br />

(Fig. 9.12). Now, we present an example in which we derive class CCylinder from class<br />

CCircle4.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!