1.abstract 的应用
1 abstract class ShapesClass 2 { 3 public abstract int Area(); 4 } 5 class Square : ShapesClass 6 { 7 int side = 0; 8 9 public Square(int n) 10 { 11 side = n; 12 } 13 // Area method is required to avoid 14 // a compile-time error. 15 public override int Area() 16 { 17 return side * side; 18 } 19 20 21 }
2.
public interface I { int M(); } public abstract class C : I { public abstract int M(); } public class Des : C { public override int M() { return 100; } }
1 Square sq = new Square(12); 2 sq.Area(); 3 int asa = new Des().M();
时间: 2024-10-21 01:33:37