File: iface4.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (82 lines) | stat: -rw-r--r-- 1,546 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;

public interface IVehicle {
	int Start ();
	int Stop ();
	int Turn ();
}

public interface IWalker {
	int Walk ();
}

public class Base : IVehicle {
	int IVehicle.Start () { return 1; }
	public int Stop () { return 2; }
	public virtual int Turn () { return 3; }
	public int Walk () { return 1; }
}

public class Derived1 : Base {
	// replaces Base.Turn + IVehice.Turn
	public override int Turn () { return 4; }
}

public class Derived2 : Base, IVehicle {
	// legal - we redeclared IVehicle support
	public new int Stop () { return 6; }
	// legal - we redeclared IVehicle support
	int IVehicle.Start () { return 5; }
	// replaces IVehicle.Turn 
	int IVehicle.Turn () { return 7; }
	// replaces Base.Turn 
	public override int Turn () { return 8; }
}

public class Derived3 : Derived1, IWalker {
}

public class Test {

	static int Main () {
		Derived1 d1 = new Derived1 ();
		Derived2 d2 = new Derived2 ();
		Derived3 d3 = new Derived3 ();
		Base b1 = d1;
		Base b2 = d2;
		Base rb = new Base ();

		if (d1.Turn () != 4)
			return 1;
		
		if (((IVehicle)d1).Turn () != 4)
			return 2;

		if (((Base)d2).Turn () != 8)
			return 10;

		if (((IVehicle)d2).Turn () != 7)
			return 3;

		if (b2.Turn () != 8)
			return 4;
		
		if (((IVehicle)b2).Turn () != 7)
			return 5;
		
		if (((IVehicle)rb).Stop () != 2)
			return 6;

		if (((IVehicle)d1).Stop () != 2)
			return 7;

		if (((IVehicle)d2).Stop () != 6)
			return 8;

		if (d3.Walk () != 1)
			return 9;

		//Console.WriteLine ("TEST {0}", ((IVehicle)b2).Turn ());
		return 0;
	}
}