📄 ch2_02.cs
字号:
using System;
class Transportation
{
private int fNumWheels;
private int fDoors;
private float fMaxSpeed;
public Transportation()
{
// Default values
fNumWheels = 4;
fDoors = 2;
fMaxSpeed = (float)55.0; // MPH
}
public int getNumberOfWheels()
{
return fNumWheels;
}
public void setNumberofWheels(int nw)
{
fNumWheels = nw;
}
public int getNumberOfDoors()
{
return fDoors;
}
public void setNumberOfDoors(int nd)
{
fDoors = nd;
}
public float getMaxSpeed()
{
return fMaxSpeed;
}
public void setMaxSpeed(float ms)
{
fMaxSpeed = ms;
}
}
class Bicycle : Transportation
{
public Bicycle()
{
setNumberofWheels(2);
setNumberOfDoors(0);
setMaxSpeed((float)15.5);
}
}
class Automobile : Transportation
{
public Automobile()
{
setNumberofWheels(4);
setNumberOfDoors(4);
setMaxSpeed((float)65.5);
}
}
class CH2_2
{
public static void Main()
{
Transportation t1 = new Transportation();
Transportation t2 = new Bicycle();
Transportation t3 = new Automobile();
Console.WriteLine("T1: # Wheels = {0}, # Doors = {1}, Max Speed = {2}",
t1.getNumberOfWheels(), t1.getNumberOfDoors(), t1.getMaxSpeed());
Console.WriteLine("T2: # Wheels = {0}, # Doors = {1}, Max Speed = {2}",
t2.getNumberOfWheels(), t2.getNumberOfDoors(), t2.getMaxSpeed());
Console.WriteLine("T3: # Wheels = {0}, # Doors = {1}, Max Speed = {2}",
t3.getNumberOfWheels(), t3.getNumberOfDoors(), t3.getMaxSpeed());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -