zoukankan      html  css  js  c++  java
  • 小知识(五):抽象类&接口

    抽象类abstract:

    抽象类和抽象方法可以用abstract关键字进行标识。就是没有完全定义的类或方法。所以不能直接实例化操作。

    就因为他没完全定义所以不能用sealed关键字进行密封。

    抽象方法不含程序主体:

        public abstract class Student

        {

            //抽象方法,不含程序体

    public abstract void GetStudentID();

    //子类可访问字段

    prodected int i;

    //定义i的属性

    public int I

    {

        get

        {

            return i;

        }

    }

    }

    继承类中实现抽象类的抽象方法

        public class ah:Student

        {

            public ah(int a)

            {

                this.i=a;

            }

            Public override void GetStudentID()

            {

                Console.writeline(i.ToString());

            }

        }

    接口interface:

        统一规划的接口。用于定义需要在子类中遵守的规范(如方法的标识)。

        同抽象类abstract不能直接实例化操作。

        接口中可以定义方法、属性或者索引器的标识

        接口中所有的成员都具有public和abstract的默认属性。接口中的方法都必须在子类中实现。

        一个类可以":"继承多个接口,一个接口可继承多个接口。

        

         public interface first

         {

         //索引器

         string this[int i]

        {

             get;

             set;

        }

        //方法

        int fun(int t);

        //属性

        string j

        {

            get;

            set;

        }

        }

    将来的你,一定会感谢现在拼命努力的你!
  • 相关阅读:
    决策树
    结巴分词demo
    线性回归分析波士顿房价
    将python的字典格式数据写入excei表中
    ubuntu16.04电脑重启/关机卡死问题记录
    Hadoop 平台搭建
    Linux 常用命令
    灰度共生矩阵
    图像类型
    linux中的一些常用命令
  • 原文地址:https://www.cnblogs.com/hugjil/p/6275216.html
Copyright © 2011-2022 走看看