using System;
namespace 接口成员隐藏
{
public interface IDrivable
{
// void Start();
// void Stop();
// bool Started
// {
// get;
// }
void TurnLeft();
}
public interface ISteerable : IDrivable
{
new void TurnLeft();
// void TurnRight();
}
// public interface IMovable : IDrivable, ISteerable
// {
// void Accelerate();
// void Brake();
// }
public class Car : ISteerable
{
// public string make;
// public string model;
// public string color;
// public int yearBuilt;
// private bool started = false;
// public void Start()
// {
// Console.WriteLine("Car started");
// started = true;
// }
// public void Stop()
// {
// Console.WriteLine("Car stopped");
// started = false;
// }
// public bool Started
// {
// get
// {
// // TODO: 添加 Car.Started getter 实现
// return started;
// }
// }
void ISteerable.TurnLeft()
{
Console.WriteLine("ISteerable implementationof TurnLeft()");
}
public void TurnLeft()
{
Console.WriteLine("IDrivable implementationof TurnLeft()");
}
// public void TurnRight()
// {
// Console.WriteLine("car turning right");
// }
//
// public void Accelerate()
// {
// Console.WriteLine("car accelerating");
// }
// public void Brake()
// {
// Console.WriteLine("car braking");
// }
}
class Example8_8
{
public static void Main()
{
Car myCar;
// Console.WriteLine("Creating a Car object and assigning " + "its memory location to myCar");
myCar = new Car();
// myCar.make = "Toyota";
// myCar.model = "MR2";
// myCar.color = "black";
// myCar.yearBuilt = 1995;
// Console.WriteLine("myCar details:");
// Console.WriteLine("myCar.make = " + myCar.make);
// Console.WriteLine("myCar.model = " + myCar.model);
// Console.WriteLine("myCar.color = " + myCar.color);
// Console.WriteLine("myCar.yearBuilt = " + myCar.yearBuilt);
// Console.WriteLine("Calling myCar.Start()");
// myCar.Start();
Console.WriteLine("Calling myCar.TurnLeft()");
myCar.TurnLeft();
ISteerable mySteerable = myCar as ISteerable;
Console.WriteLine("Calling mySteerable.TurnLeft()");
mySteerable.TurnLeft();
IDrivable myDrivable = myCar as IDrivable;
Console.WriteLine("Calling myDrivable.TurnLeft()");
myDrivable.TurnLeft();
// Console.WriteLine("Callng myCar.Accelerate()");
// myCar.Accelerate();
// Car redPorsche = new Car();
// Console.WriteLine("Creating another Car object and " + "assigning its memory location to redPorsche");
// redPorsche.make = "Porsche";
// redPorsche.model = "Boxster";
// redPorsche.color = "red";
// redPorsche.yearBuilt = 2000;
// Console.WriteLine("redPorsche is a " + redPorsche.model);
// Console.WriteLine("Assigning redPorsche to myCar");
// myCar = redPorsche;
// Console.WriteLine("myCar details:");
// Console.WriteLine("myCar.make = " + myCar.make);
// Console.WriteLine("myCar.model = " + myCar.model);
// Console.WriteLine("myCar.color = " + myCar.color);
// Console.WriteLine("myCar.yearBuilt = " + myCar.yearBuilt);
Console.ReadLine();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Visual C#.NET 从入门到精通5-8.rar (44个子文件)
Visual C#.NET 从入门到精通5-8
6-类和对象
Example6_6.txt 924B
Example6_4.txt 529B
Example6_1.txt 752B
Example6_8.txt 692B
Example6_7.txt 744B
Example6_9.txt 183B
Example6_5.txt 916B
Example6_2.txt 247B
Example6_3.txt 484B
8-接口
Example8_4.txt 3KB
Example8_3.txt 3KB
Example8_5.txt 2KB
Example8_7.txt 3KB
Example8_8.txt 3KB
Example8_6.txt 3KB
Example8_1.txt 2KB
Example8_2.txt 2KB
7-派生类
Example7_1.txt 1KB
Example7_12.txt 2KB
Example7_4.txt 1KB
Example7_11.txt 2KB
Example7_6.txt 2KB
Example7_7.txt 807B
Example7_9.txt 1KB
Example7_2.txt 1KB
Example7_8.txt 513B
Example7_5.txt 913B
Example7_3.txt 828B
Example7_10.txt 1KB
5-面向对象的编程
Example5_14.txt 312B
Example5_04.txt 1KB
Example5_02.txt 1022B
Example5_07.txt 632B
Example5_15.txt 690B
Example5_10.txt 1KB
Example5_09.txt 1KB
Example5_06.txt 674B
Example5_05.txt 564B
Example5_08.txt 525B
Example5_01.txt 2KB
Example5_03.txt 908B
Example5_12.txt 1KB
Example5_13.txt 1KB
Example5_11.txt 853B
共 44 条
- 1
资源评论
- 展现风采2014-03-21对初学者来说 不错
- jiaojh2011-11-07可以省略输入过程了,
West__M
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功