zoukankan      html  css  js  c++  java
  • 当抽象(abstract)遇上静态后(static)

    看SqlHelper的代码时,类是一个抽象类,里面用的都是静态方法,在调用的时候直接就用了 (抽象类.静态方法)

    因为以前抽象类都是说不可以实例化的,实例化和静态之间有关系么?

    做了一个实例,证实静态类可以直接被调用,无论是抽象类,继承类,还是普通类,都可以。

    代码如下

    using System;

    namespace AbstractStatic
    {
        
    class Program
        {
            
    public static void Main(string[] args)
            {
                abs.show();
                absNext.show();
                normal.show();
                
                
                
                
    // TODO: Implement Functionality Here
                
                Console.Write(
    "Press any key to continue . . . ");
                Console.ReadKey(
    true);
            }
            
    abstract class abs
            {
                
    public static void show()
                {
                    Console.WriteLine(
    "我是抽象类里的静态类");
                }
                
    public void show2()
                {
                    Console.WriteLine(
    "我是抽象类里的非静态类");
                }
            }
            
    class absNext: abs
            {
                
    public new static void show()
                {
                    Console.WriteLine(
    "我是继承类里的静态类");
                }
            }
            
    class normal
            {
                
    public static void show()
                {
                    Console.WriteLine(
    "我是非抽象类里的静态类");
                }
                
    public void show2()
                {
                    Console.WriteLine(
    "我是非抽象类里的非静态类");
                }
            }

    静态方法还是很方便的,呵呵。。。。

    本人菜鸟,遇到的都是不足挂齿小问题,大家别拍我撒。。。

  • 相关阅读:
    【python】python中的定义类属性和对像属性
    【Python】Python—判断变量的基本类型
    【python】Python中给List添加元素的4种方法分享
    【python】python各种类型转换-int,str,char,float,ord,hex,oct等
    【python】python 中的三元表达式(三目运算符)
    【python】 sort、sorted高级排序技巧
    【SQLAlchemy】SQLAlchemy技术文档(中文版)(中)
    【SQLAlchemy】SQLAlchemy技术文档(中文版)(上)
    【其他】VS提示不一致的行尾
    UML 之 用例图
  • 原文地址:https://www.cnblogs.com/tombaur/p/1352355.html
Copyright © 2011-2022 走看看