Little knowledge of C# (5): Abstract classes & interfaces

黄舟
Release: 2017-02-07 15:18:22
Original
1147 people have browsed it

Abstract class abstract:

Abstract classes and abstract methods can be identified with the abstract keyword. There is no fully defined class or method. Therefore, the instantiation operation cannot be directly performed.

Because it is not fully defined, it cannot be sealed with the sealed keyword.

Abstract methods do not contain the program body:

 public abstract class Student
    {
        //抽象方法,不含程序体
public abstract void GetStudentID();
//子类可访问字段
prodected int i;
//定义i的属性
public int I
{
    get
    {
        return i;
    }
}
}
Copy after login

Abstract methods that implement abstract classes in inherited classes

 public class ah:Student
    {
        public ah(int a)
        {
            this.i=a;
        }
        Public override void GetStudentID()
        {
            Console.writeline(i.ToString());
        }
    }
Copy after login

Interface interface:

Unified planned interface. Used to define specifications that need to be followed in subclasses (such as method identification).

The same abstract class abstract cannot be directly instantiated.

The interface can define the identification of methods, properties or indexers.

All members in the interface have the default attributes of public and abstract. All methods in the interface must be implemented in subclasses.

A class can ":" inherit multiple interfaces, and one interface can inherit multiple interfaces.

   public interface first
     {
     //索引器
     string this[int i]
    {
         get;
         set;
    }
    //方法
    int fun(int t);
    //属性
    string j
    {
        get;
        set;
    }
    }
Copy after login

The above is the little knowledge of C# (5): the content of abstract classes & interfaces. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
c#
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!