C#接口练习

 1 /*接口的实现例子
 2  * 2016年2月23日11:07:11
 3 */
 4 using System;
 5 using System.Collections.Generic;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 
10 namespace Demo5
11 {
12     class Program
13     {
14         static void Main(string[] args)
15         {
16             //用接口实例化一个类对象
17             IFlyable sp = new SuperMan();
18             sp.Fly();
19             sp.Jump();
20             Console.ReadKey();
21         }
22     }
23     
24     //接口声明用interface关键字
25     //方法可以没有任何实现,接口中只能包含方法
26     //接口中的成员不能带有任何修辞符,默认是public,但是不是写下去,会报错
27     public interface IFlyable
28     {
29         void Fly(); // 方法前不能带任何修辞符,默认是public
30         void Jump();
31       }
32 
33     //定义一个类去实现接口
34     class SuperMan : IFlyable
35     {
36         //直接写方法,不需要使用override
37         public void Fly()
38         {
39             Console.WriteLine("Surperman can fly");
40         }
41 
42         public void Jump()
43         {
44             Console.WriteLine("Surperman can jump");
45         }
46     }
47 }

 

posted on 2016-02-23 13:31 低音炮可怕男子 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/DreamTime/p/5209609.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值