using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Interface
{
class Program
{
public interface Ifire
{
void fire();
void yongbao();
}
public class Tank : Ifire
{
public void fire()
{
Console.WriteLine("我是坦克,我要开火");
}
}
static void Main(string[] args)
{
Tank ta = new Tank();
ta.fire();
}
}
}
此编译不能通过
错误 1 “Interface.Program.Tank”不实现接口成员“Interface.Program.Ifire.yongbao()” F:\my control program\ConsoleApplication3\ConsoleApplication3\Program.cs 15 22 ConsoleApplication3
解释:因为接口还定义了yongbao方法,子类继承了接口,而子类没用yongbao这个方法,所以会报错。
浙公网安备 33010602011771号