 2002 Prentice Hall. All rights reserved. 1 Chapter 9 – Object-Oriented Programming: Inheritance Outline 9.1Introduction 9.2Base Classes and Derived Classes.

Slides:



Advertisements
Similar presentations
Outline 1 Introduction 2 Base Classes and Derived Classes 3 protected Members 4 Relationship between Base Classes and Derived Classes 5 Case Study: Three-Level.
Advertisements

Chapter 19 - Inheritance Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Object-Oriented Programming: Polymorphism Outline 10.1 Introduction 10.2 Relationships Among.
Chapter 20- Virtual Functions and Polymorphism Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng.
Shape.h Shape Point Circle Cylinder // SHAPE.H
Esempi Ereditarietà1 // Definition of class Point #ifndef POINT_H #define POINT_H #include using std::ostream; class Point { friend ostream &operator
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Base Classes and Derived.
1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Superclasses and Subclasses 9.3 protected Members 9.4 Relationship.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Superclasses and Subclasses.
 2002 Prentice Hall. All rights reserved. Some slides modified by LL 1 Chapter 9 – Object-Oriented Programming: Inheritance Outline 9.1Introduction 9.2Base.
 2009 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance Many slides modified by Prof. L. Lilien (even many without.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20- Virtual Functions and Polymorphism Outline 20.1Introduction 20.2Type Fields and switch Statements.
Properties Methods of a class can manipulate that class’s private data members Methods of a class can manipulate that class’s private data members Classes.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 19 - Inheritance Outline 19.1Introduction 19.2Inheritance: Base Classes and Derived Classes 19.3Protected.
1 Review (Week7)_ Classes Part II Outline Composition: Objects as Members of Classes Dynamic Memory static Class Members Operator Overloading.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Inheritance Outline 9.1Introduction 9.2Inheritance: Base Classes and Derived Classes 9.3.
1 Lecture Note 9_Polymorphism Outline Relationships Among Objects in an Inheritance Hierarchy Invoking Base-Class Functions from Derived-Class object Virtual.
 2002 Prentice Hall. All rights reserved. 1 Chapter 10 – Object-Oriented Programming: Polymorphism Outline 10.1 Introduction 10.2 Derived-Class-Object.
 2002 Prentice Hall. All rights reserved. Page 1 Chapter 9 - Object-Oriented Programming 9.10 Introduction to Polymorphism 9.11 Type Fields and switch.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 1: Course overview.
 2002 Prentice Hall. All rights reserved. Chapter 9 - Object-Oriented Programming Outline 9.1 Introduction 9.2 Superclasses and Subclasses 9.3 protected.
 2002 Prentice Hall. All rights reserved. 1 Introduction to Inheritance Inheritance: –1 of 3 main features of OOP –Form of software reusability –(Derived)
1 Advanced Programming Lecture 5 Inheritance. 2 static Class Members Every object of a class has its own copy of all instance variables Sometimes it is.
 2002 Prentice Hall. All rights reserved. 1 Chapter 9 – Object-Oriented Programming: Inheritance Outline 9.1Introduction 9.2Base Classes and Derived Classes.
 2002 Prentice Hall. All rights reserved. 1 Chapter 10 – Object-Oriented Programming: Polymorphism Outline 10.1 Introduction 10.2 Derived-Class-Object.
 2002 Prentice Hall. All rights reserved. 1 Chapter 9 – Object-Oriented Programming: Inheritance Outline 9.1Introduction 9.2 Base Classes and Derived.
 2003 Prentice Hall, Inc. All rights reserved 1 Object-Oriented Programming Inheritance Main Objectives: To understand how inheritance.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 19 - C++ Inheritance Outline 19.1Introduction.
1 OOP : main concepts Polymorphism. 2 OOP : main concepts  The main concepts:  In a superclass –public members Accessible anywhere program has a reference.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 20 - C++ Virtual Functions and Polymorphism.
 2003 Prentice Hall, Inc. All rights reserved Case Study: Three-Level Inheritance Hierarchy Three level point/circle/cylinder hierarchy –Point.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 19 – Inheritance Part 2 Outline 19.8Direct Base Classes and Indirect Base Classes 19.9Using Constructors.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Inheritance Outline 9.1Introduction 9.2Inheritance: Base Classes and Derived Classes 9.3.
 2002 Prentice Hall. All rights reserved. Modifed by Haytham Allos, NYU CSD V Week 2 - Object-Oriented Programming Outline 2.1 Introduction 2.2.
 2002 Prentice Hall. All rights reserved. 1 Introduction Polymorphism allows programmers to write: –Programs that handle a wide variety of related classes.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Superclasses and Subclasses.
 2002 Prentice Hall. All rights reserved. 1 Chapter 10 – Object-Oriented Programming: Polymorphism Outline 10.1 Introduction 10.2 Derived-Class-Object.
String 1. 2 Char Methods For the char value type, there is a Char class Most methods are static –IsLetter –IsDigit –IsLetterOrDigit –IsLower –IsUpper.
 2002 Prentice Hall. All rights reserved. 1 Week 4: OOP Questions from last lecture: –Single-subscript arrays –Multiple-subscript arrays –Homework/Practical.
/** Feb 1996 Cay Horstmann */ import java.util.*; import corejava.*; public class EmployeeTest { public static void main(String[]
 2002 Prentice Hall. All rights reserved. 1 Chapter 10 – Object-Oriented Programming: Part 2 Outline 10.1Introduction 10.2 Derived-Class-Object to Base-Class-Object.
Jozef Goetz contribution,  2011 Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved.
 2003 Prentice Hall, Inc. All rights reserved Case Study: Three-Level Inheritance Hierarchy Three level point/circle/cylinder hierarchy –Point.
 2003 Prentice Hall, Inc. All rights reserved Virtual Functions Polymorphism –Same message, “print”, given to many objects All through a base.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
 2002 Prentice Hall. All rights reserved. 1 Chapter 11 – [Object-Oriented Programming] Polymorphism, Interfaces & Operator Overloading Section [order.
Jozef Goetz contribution,  2011, 2014 Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 19 – Inheritance – Part 1 Outline 19.1Introduction 19.2Inheritance: Base Classes and Derived Classes.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20 - Polymorphism Outline 20.5Polymorphism 20.6Case Study: A Payroll System Using Polymorphism.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Base Classes and Derived.
Jozef Goetz contribution, Credits go to  2014, 2011, 2009 Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved.
 2009 Prentice Hall. All rights reserved. 1 Chapter 12 Polymorphism, Interfaces & Operator Overloading [optional] Many slides modified by Prof. L. Lilien.
 2002 Prentice Hall. All rights reserved. Page 1 Inheritance: Object-Oriented Programming Outline 9.1 Introduction 9.2 Superclasses and Subclasses 9.3.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Object-Oriented Programming: Polymorphism.
1 Inheritance inheritance –a mechanism that build a new class by deriving from an existing class –derived class (or subclass) inherit from based class.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Base Classes and Derived.
Abstract classes only used as base class from which other classes can be inherit cannot be used to instantiate any objects are incomplete Classes that.
Chapters 9, 10 – Object-Oriented Programming: Inheritance
Chapter 9 - Object-Oriented Programming: Inheritance
Questions from last lesson
Chapter 9 – Object-Oriented Programming: Inheritance
 2002 Prentice Hall. All rights reserved.
Object-Oriented Programming: Inheritance
Week 6 Object-Oriented Programming (2): Polymorphism
Chapter 9 - Object-Oriented Programming: Inheritance
Chapter 20- Virtual Functions and Polymorphism
Polymorphism, Interfaces &
Chapter 20 - C++ Virtual Functions and Polymorphism
Chapter 9 - Object-Oriented Programming: Inheritance
Virtual Functions Example
Presentation transcript:

 2002 Prentice Hall. All rights reserved. 1 Chapter 9 – Object-Oriented Programming: Inheritance Outline 9.1Introduction 9.2Base Classes and Derived Classes 9.3 protected Members 9.4Creating Base Classes and Derived Classes 9.5Constructors and Destructors in Derived Classes 9.6Software Engineering with Inheritance 9.7Case Study: Point, Circle, Cylinder

 2002 Prentice Hall. All rights reserved Base Classes and Derived Classes

 2002 Prentice Hall. All rights reserved Base Classes and Derived Classes Fig. 9.2Inheritance hierarchy for university CommunityMember s. CommunityMemeber EmployeeStudentAlumnus FacultyStaff AdministratorTeacher

 2002 Prentice Hall. All rights reserved Base Classes and Derived Classes Fig. 9.3Portion of a Shape class hierarchy. Shape TwoDimensionalShapeThreeDimensionalShape SphereCubeCylinderTriangleSquareCircle

 2002 Prentice Hall. All rights reserved. Outline 5 Point.cs 1 // Fig. 9.4: Point.cs 2 // Class Point maintains an X and Y coordinate. 3 4 using System; 5 6 // Point class definition 7 public class Point 8 { 9 // point coordinate 10 protected int xCoordinate, yCoordinate; // default constructor 13 public Point() 14 { 15 // implicit call to base class constructor occurs here 16 X = 0; 17 Y = 0; 18 } // constructor 21 public Point( int xValue, int yValue ) 22 { 23 // implicit call to base class constructor occurs here 24 X = xValue; 25 Y = yValue; 26 } // property X 29 public int X 30 { 31 get 32 { 33 return xCoordinate; 34 } 35

 2002 Prentice Hall. All rights reserved. Outline 6 Point.cs Program Output 36 set 37 { 38 xCoordinate = value; 39 } 40 } // property Y 43 public int Y 44 { 45 get 46 { 47 return yCoordinate; 48 } set 51 { 52 yCoordinate = value; 53 } 54 } // return string representation of Point 57 public override string ToString() 58 { 59 return "[" + X + ", " + Y + "]"; 60 } } // end class Point

 2002 Prentice Hall. All rights reserved. Outline 7 PointTest.cs 1 // Fig. 9.5: PointTest.cs 2 // Manipulating a Point object. 3 4 using System; 5 using System.Windows.Forms; 6 7 // PointTest class definition 8 class PointTest 9 { 10 // main entry point for application 11 static void Main( string[] args ) 12 { 13 Point point = new Point( 72, 115 ); // append initial Point coordinates to output 16 string output = "X coordinate: " + point.X + 17 "\nY coordinate: " + point.Y; // set new coordinates 20 point.X = 10; 21 point.Y = 10; // append new Point coordinates to output 24 output += "\n\nNew location of point: " + 25 point.ToString() + "\nImplicit ToString call: " + 26 point; MessageBox.Show( output, "Demonstrating Class Point" ); } // end method Main } // end class PointTest

 2002 Prentice Hall. All rights reserved. Outline 8 Circle.cs 1 // Fig. 9.6: Circle.cs 2 // Class Circle maintains a radius and X and Y coordinates 3 // representing a circle's center. 4 5 using System; 6 7 // Circle class definition 8 public class Circle 9 { 10 // coordinates of circle center 11 protected int xCoordinate, yCoordinate; // radius of circle 14 protected double radius; // default constructor 17 public Circle() 18 { 19 // implicit call to base class constructor occurs here 20 X = 0; 21 Y = 0; 22 Radius = 0.0; 23 } // constructor 26 public Circle( int xValue, int yValue, double radiusValue ) 27 { 28 // implicit call to base class constructor occurs here 29 X = xValue; 30 Y = yValue; 31 Radius = radiusValue; 32 } 33

 2002 Prentice Hall. All rights reserved. Outline 9 Circle.cs 34 // property X 35 public int X 36 { 37 get 38 { 39 return xCoordinate; 40 } set 43 { 44 xCoordinate = value; 45 } 46 } // property Y 49 public int Y 50 { 51 get 52 { 53 return yCoordinate; 54 } set 57 { 58 yCoordinate = value; 59 } 60 } // property Radius 63 public double Radius 64 { 65 get 66 { 67 return radius; 68 }

 2002 Prentice Hall. All rights reserved. Outline 10 Circle.cs set 71 { 72 radius = ( value >= 0.0 ? value : 0.0 ); 73 } 74 } // return area of Circle 77 public double Area() 78 { 79 return Math.PI * radius * radius; 80 } // return string representation of Circle 83 public override string ToString() 84 { 85 return "Center = [" + X + ", " + Y + 86 "]; Radius = " + radius; 87 } } // end class Circle

 2002 Prentice Hall. All rights reserved. Outline 11 CircleTest.cs 1 // Fig. 9.7: CircleTest.cs 2 // Manipulating a Circle object. 3 4 using System; 5 using System.Windows.Forms; 6 7 // CircleTest class definition 8 class CircleTest 9 { 10 // main entry point for application 11 static void Main( string[] args ) 12 { 13 Circle circle = new Circle( 37, 43, 2.5 ); // append Circle properties to output 16 string output = "X coordinate: " + circle.X + 17 "\nY coordinate: " + circle.Y + 18 "\nRadius: " + circle.Radius; // set new coordinates and radius 21 circle.X = 10; 22 circle.Y = 10; 23 circle.Radius = 4.25; // append new Point coordinates to output 26 output += "\n\nNew location and radius of circle: " + 27 circle.ToString() + 28 "\nImplicit ToString call: " + circle + "\nArea: " + 29 String.Format( "{0:F2}", circle.Area() ); MessageBox.Show( output, "Demonstrating Class Circle" ); } // end method Main } // end class CircleTest

 2002 Prentice Hall. All rights reserved. Outline 12 CircleTest.cs Program Output

 2002 Prentice Hall. All rights reserved. Outline 13 Circle.cs 1 // Fig. 9.8: Circle.cs 2 // Class Circle inherits from Point. 3 4 using System; 5 6 // Circle class definition 7 public class Circle : Point 8 { 9 // radius of circle 10 protected double radius; // default constructor 13 public Circle() 14 { 15 // implicit call to base class constructor occurs here 16 Radius = 0.0; 17 } // constructor 20 public Circle( int xValue, int yValue, double radiusValue ) 21 : base( xValue, yValue ) 22 { 23 Radius = radiusValue; 24 } // property Radius 27 public double Radius 28 { 29 get 30 { 31 return radius; 32 } 33

 2002 Prentice Hall. All rights reserved. Outline 14 Circle.cs 34 set 35 { 36 radius = ( value >= 0.0 ? value : 0.0 ); 37 } 38 } // return area of Circle 41 public double Area() 42 { 43 return Math.PI * radius * radius; 44 } // return string representation of Circle 47 public override string ToString() 48 { 49 return "Center = [" + xCoordinate + ", " + yCoordinate + 50 "]; Radius = " + radius; 51 } } // end class Circle

 2002 Prentice Hall. All rights reserved. Outline 15 Point.cs 1 // Fig. 9.9: Point.cs 2 // Class Point maintains an X and Y coordinate. 3 4 using System; 5 6 // Point class definition 7 public class Point 8 { 9 // point coordinate 10 protected int xCoordinate, yCoordinate; // default constructor 13 public Point() 14 { 15 // implicit call to base class constructor occurs here 16 X = 0; 17 Y = 0; 18 Console.WriteLine( "Point constructor: " + this ); 19 } // constructor 22 public Point( int xValue, int yValue ) 23 { 24 // implicit call to base class constructor occurs here 25 X = xValue; 26 Y = yValue; 27 Console.WriteLine( "Point constructor: " + this ); 28 } // destructor 31 ~Point() 32 { 33 Console.WriteLine( "Point destructor: " + this ); 34 } 35

 2002 Prentice Hall. All rights reserved. Outline 16 Point.cs 36 // property X 37 public int X 38 { 39 get 40 { 41 return xCoordinate; 42 } set 45 { 46 xCoordinate = value; 47 } 48 } // property Y 51 public int Y 52 { 53 get 54 { 55 return yCoordinate; 56 } set 59 { 60 yCoordinate = value; 61 } 62 } // return string representation of Point 65 public override string ToString() 66 { 67 return "[" + X + ", " + Y + "]"; 68 } } // end class Point

 2002 Prentice Hall. All rights reserved. Outline 17 Circle.cs 1 // Fig. 9.10: Circle.cs 2 // Class Circle inherits from Point. 3 4 using System; 5 6 // Circle class definition 7 public class Circle : Point 8 { 9 // radius of circle 10 protected double radius; // default constructor 13 public Circle() 14 { 15 // implicit call to base class constructor occurs here 16 Radius = 0.0; 17 Console.WriteLine( "Circle constructor: " + this ); 18 } // constructor 21 public Circle( int xValue, int yValue, double radiusValue ) 22 : base( xValue, yValue ) 23 { 24 Radius = radiusValue; 25 Console.WriteLine( "Circle constructor: " + this ); 26 } // destructor 29 ~Circle() 30 { 31 Console.WriteLine( "Circle destructor: " + this ); 32 } 33

 2002 Prentice Hall. All rights reserved. Outline 18 Circle.cs 34 // property Radius 35 public double Radius 36 { 37 get 38 { 39 return radius; 40 } set 43 { 44 radius = ( value >= 0.0 ? value : 0.0 ); 45 } 46 } // return string representation of Circle 49 public override string ToString() 50 { 51 return "Center = " + base.ToString() + 52 "; Radius = " + radius; 53 } } // end class Circle

 2002 Prentice Hall. All rights reserved. Outline 19 ConstructorAndDe structor.cs 1 // Fig. 9.11: ConstructorAndDestructor.cs 2 // Demonstrating the order in which base-class and 3 // derived-class constructors and destructors are called. 4 5 using System; 6 7 // ConstructorAndDestructor class definition 8 class ConstructorAndDestructor 9 { 10 // main entry point for application 11 static void Main( string[] args ) 12 { 13 Circle circle1 = new Circle( 72, 29, 4.5 ); Console.WriteLine(); Circle circle2 = new Circle( 5, 5, 10 ); Console.WriteLine(); // remove references to Circle objects 22 circle1 = null; 23 circle2 = null; System.GC.Collect(); } // end method Main } // end class ConstructorAndDestructor

 2002 Prentice Hall. All rights reserved. Outline 20 ConstructorAndDe structor.cs Program Output Point constructor: Center = [72, 29]; Radius = 0 Circle constructor: Center = [72, 29]; Radius = 4.5 Point constructor: Center = [5, 5]; Radius = 0 Circle constructor: Center = [5, 5]; Radius = 10 Circle destructor: Center = [5, 5]; Radius = 10 Point destructor: Center = [5, 5]; Radius = 10 Circle destructor: Center = [72, 29]; Radius = 4.5 Point destructor: Center = [72, 29]; Radius = 4.5

 2002 Prentice Hall. All rights reserved. Outline 21 Circle.cs 1 // Fig. 9.12: Circle.cs 2 // Class Circle inherits from Point. 3 4 using System; 5 6 // Circle class definition 7 public class Circle : Point 8 { 9 // radius of circle 10 protected double radius; // default constructor 13 public Circle() 14 { 15 // implicit call to base class constructor occurs here 16 Radius = 0.0; 17 } // constructor 20 public Circle( int xValue, int yValue, double radiusValue ) 21 : base( xValue, yValue ) 22 { 23 Radius = radiusValue; 24 } // property Radius 27 public double Radius 28 { 29 get 30 { 31 return radius; 32 } 33

 2002 Prentice Hall. All rights reserved. Outline 22 Circle.cs 34 set 35 { 36 radius = ( value >= 0.0 ? value : 0.0 ); 37 } 38 } // return area of Circle 41 public virtual double Area() 42 { 43 return Math.PI * radius * radius; 44 } // return string representation of Circle 47 public override string ToString() 48 { 49 return "Center = " + base.ToString() + 50 "; Radius = " + radius; 51 } } // end class Circle

 2002 Prentice Hall. All rights reserved. Outline 23 CircleTest2.cs 1 // Fig. 9.13: CircleTest2.cs 2 // Manipulating a Circle object. 3 4 using System; 5 using System.Windows.Forms; 6 7 // CircleTest class definition 8 class CircleTest2 9 { 10 // main entry point for application 11 static void Main( string[] args ) 12 { 13 Circle circle = new Circle( 37, 43, 2.5 ); // append Circle properties to output 16 string output = "X coordinate: " + circle.X + 17 "\nY coordinate: " + circle.Y + 18 "\nRadius: " + circle.Radius; // set new coordinates and radius 21 circle.X = 10; 22 circle.Y = 10; 23 circle.Radius = 4.25; // append new Point coordinates to output 26 output += "\n\nNew location and radius of circle: " + 27 circle.ToString() + 28 "\nImplicit ToString call: " + circle + "\nArea: " + 29 String.Format( "{0:F2}", circle.Area() ); MessageBox.Show( output, "Demonstrating Class Circle" ); } // end method Main } // end class CircleTest2

 2002 Prentice Hall. All rights reserved. Outline 24 CircleTest2.cs Program Output

 2002 Prentice Hall. All rights reserved. Outline 25 Cylinder.cs 1 // Fig. 9.14: Cylinder.cs 2 // Class Cylinder inherits from Circle. 3 4 using System; 5 6 // Cylinder class definition 7 public class Cylinder : Circle 8 { 9 protected double height; // default constructor 12 public Cylinder() 13 { 14 // implicit call to base class constructor occurs here 15 Height = 0.0; 16 } // constructor 19 public Cylinder( int xValue, int yValue, 20 double radiusValue, double heightValue ) 21 : base( xValue, yValue, radiusValue ) 22 { 23 Height = heightValue; 24 } // property Height 27 public double Height 28 { 29 get 30 { 31 return height; 32 } 33

 2002 Prentice Hall. All rights reserved. Outline 26 Cylinder.cs 34 set 35 { 36 height = ( value >= 0.0 ? value : 0.0 ); 37 } 38 } // return area of Cylinder 41 public override double Area() 42 { 43 return 2 * base.Area() + 2 * Math.PI * radius * radius; 44 } // return volume of Cylinder 47 public double Volume() 48 { 49 return base.Area() * height; 50 } // return string representation of Cylinder 53 public override string ToString() 54 { 55 return base.ToString() + "; Heigth = " + height; 56 } } // end class Cylinder

 2002 Prentice Hall. All rights reserved. Outline 27 CylinderTest.cs 1 // Fig. 9.15: CylinderTest.cs 2 // Manipulating a Cylinder object. 3 4 using System; 5 using System.Windows.Forms; 6 7 // CylinderTest class definition 8 class CylinderTest 9 { 10 // main entry point for application 11 static void Main( string[] args ) 12 { 13 Cylinder cylinder = new Cylinder( 12, 23, 2.5, 5.7 ); // append Cylinder properties to output 16 string output = "X coordinate: " + cylinder.X + 17 "\nY coordinate: " + cylinder.Y + 18 "\nRadius: " + cylinder.Radius + 19 "\nHeight: " + cylinder.Height; // set new coordinates and radius 22 cylinder.X = 10; 23 cylinder.Y = 10; 24 cylinder.Radius = 10; 25 cylinder.Height = 4.25; // append new Point coordinates to output 28 output += 29 "\n\nNew location, radius and height of cylinder: " + 30 cylinder.ToString() + "\nImplicit ToString call: " + 31 cylinder + "\nArea: " + 32 String.Format( "{0:F2}", cylinder.Area() ) + 33 "\nVolume: " + 34 String.Format( "{0:F2}", cylinder.Volume() ); 35

 2002 Prentice Hall. All rights reserved. Outline 28 CylinderTest.cs Program Output 36 MessageBox.Show( output, "Demonstrating Class Cylinder" ); } // end method Main } // end class CylinderTest