Initial set of Ward sgen annotations (#5705)
[mono.git] / mono / tests / interface.cs
1 using System;
2
3 namespace Obj {
4         interface Measurable {
5                 double Area ();
6         };
7         class Obj : Measurable {
8                 public double Area () {
9                         return 0.0;
10                 }
11         };
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;
19                 }
20                 public new double Area () {
21                         return (double)w*h;
22                 }
23         }
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;
30                 }
31                 public new double Area () {
32                         return r*r*System.Math.PI;
33                 }
34         }
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;
54                 }
55         };
56 };