c#基础练习(多态之接口)
发布时间
阅读量:
阅读量
接口定义
接口体现的是一种规范性要求,同时也代表了一种实现能力。
语法:
public interface ICanRunable
{
void Run();
}
AI写代码csharp
接口内的方法无需指定访问权限修饰符,其默认访问级别为public。
方法定义中不得包含具体实现内容。
接口中可包含方法、自动属性以及索引器,因其在本质上均可视为方法的体现。
using System;
namespace 接口
{
class Program
{
static void Main(string[] args)
{
ICanRunable p=new Student(111, 20, "王五");
p.Run();
Console.Read();
}
}
class Person:ICanRunable
{
public string Name { get; set; }
public int
全部评论 (0)
还没有任何评论哟~
