C# 抽象类其中创建一个静态方法

</pre><pre name="code" class="csharp"><span style="font-size:18px;">public class TestMain {  
    public static void main(String[] args)  
    {  
        AbstractTest.out();  
    }  
}  </span>

<span style="font-size:18px;">public class TestMain {  
    public static void main(String[] args)  
    {  
        AbstractTest.out();  
    }  
}  </span>

如上面的程序所看到的是能够执行的。

理解:普通情况下抽象类中能够包括抽象方法和非抽象方法。静态类中仅仅能包括静态成员,全部的静态成员也仅仅能包括在静态类中。

由于静态static的本质是包括abstract和sealed的。所以静态方法能够包括在抽象类中。并通过抽象类名.静态方法  来使用该方法。又由于静态包括sealed特性,所以不能够被继承。

       事实上这样就能够避免由于抽象类不能实例化而必须在其子类中实例化对象来使用父类中的方法,能够直接将方法写成静态方法,就能够不使用抽象类的子类来实现方法。

版权声明:本文博客原创文章,博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/mfrbuaa/p/4682664.html