[interp] Remove unreachable code (#12411)
[mono-project.git] / mono / tests / interface.cs
blob5c2a861135169974c8b111793b933dae3b50521a
1 using System;
3 namespace Obj {
4 interface Measurable {
5 double Area ();
6 };
7 class Obj : Measurable {
8 public double Area () {
9 return 0.0;
12 class Rect : Obj {
13 int x, y, w, h;
14 public Rect (int vx, int vy, int vw, int vh) {
15 x = vx;
16 y = vy;
17 w = vw;
18 h = vh;
20 public new double Area () {
21 return (double)w*h;
24 class Circle : Obj {
25 int x, y, r;
26 public Circle (int vx, int vy, int vr) {
27 x = vx;
28 y = vy;
29 r = vr;
31 public new double Area () {
32 return r*r*System.Math.PI;
35 class Test {
36 static public int Main () {
37 Obj rect, circle;
38 double sum;
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... */
43 if (sum != 0.0)
44 return 1;
45 /* now call the derived methods */
46 sum = ((Rect)rect).Area() + ((Circle)circle).Area ();
47 if (sum != (200 + 400*System.Math.PI))
48 return 2;
49 /* let's try to cast to the interface, instead */
50 sum = ((Measurable)rect).Area() + ((Measurable)circle).Area ();
51 if (sum != 0.0)
52 return 3;
53 return 0;