7 class Obj
: Measurable
{
8 public double Area () {
14 public Rect (int vx
, int vy
, int vw
, int vh
) {
20 public new double Area () {
26 public Circle (int vx
, int vy
, int vr
) {
31 public new double Area () {
32 return r
*r
*System
.Math
.PI
;
36 static public int Main () {
39 rect
= new Rect (0, 0, 10, 20);
40 circle
= new Circle (0, 0, 20);
41 sum
= rect
.Area() + circle
.Area ();
42 /* surprise! this calls Obj.Area... */
45 /* now call the derived methods */
46 sum
= ((Rect
)rect
).Area() + ((Circle
)circle
).Area ();
47 if (sum
!= (200 + 400*System
.Math
.PI
))
49 /* let's try to cast to the interface, instead */
50 sum
= ((Measurable
)rect
).Area() + ((Measurable
)circle
).Area ();