//using the idea of object-oriented polymorphism to find the area and perimeter of circle and rectangle respectivelyStatic voidMain (string[] args) { Sharp Sharp=NewCircle (5); DoubleArea=Sharp . Getarea (); DoublePerimeter=Sharp . Getperimeter (); Console.WriteLine ("area is {0}, perimeter is {1}", Area,perimeter); Console.readkey (); } Public Abstract classSharp { Public Abstract DoubleGetarea (); Public Abstract DoubleGetperimeter (); } Public classCircle:sharp {Private Double_r; Public DoubleR {Get{return_r;} Set{_r =value;} } PublicCircle (Doubler) { This. R =R; } Public Override DoubleGetarea () {returnMath.PI * This. R This. R } Public Override DoubleGetperimeter () {return 2* Math.PI * This. R } } Public classSquare:sharp {Private Double_height; Public DoubleHeight {Get{return_height;} Set{_height =value;} } Private Double_width; Public DoubleWidth {Get{return_width;} Set{_width =value;} } PublicSquare (DoubleHeightDoublewidth) { This. Height =height; This. Width =width; } Public Override DoubleGetarea () {return This. Height * This. Width; } Public Override DoubleGetperimeter () {return( This. Height + This. Width) *2; } }
Using the idea of object-oriented polymorphism to find the area and perimeter of circle and rectangle respectively