首页 > 代码库 > abstract和interface

abstract和interface

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         }
View Code

 

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();

 

abstract和interface