正如你们从代码中看到的那样,我创建了三类汽车,新模型,主要。所有基本方法都在汽车类中,我创建了继承类来尝试(继承)。正如你所看到的,我正在做的只是输出 car 类的 wheel() 方法和 newmodel 继承类的 newrims() 方法来做一个完整的句子。需要建议使代码更准确。
namespace ConsoleApplication4
{
public class car
{
public static void wheel()
{
Console.WriteLine("The wheels are rolling");
}
public static void doors()
{
Console.WriteLine("The Doors are automatic");
}
public static void engine()
{
Console.WriteLine("The engine of car is runing");
}
public static void oil()
{
Console.WriteLine("the oil is full in tank");
}
}
public class newmodel : car
{
public static void newrims()
{
car.wheel();
Console.WriteLine("And The new rims are rocking");
}
}
class Program
{
static void Main()
{
while (true)
{
Console.WriteLine("Press A to Roll the Wheels baby");
Console.WriteLine("Press B to Open/Close the Doors");
Console.WriteLine("Press C to Start the Car Engine");
Console.WriteLine("Press D to Check the Oil in tank");
Console.WriteLine("Press E to Rims/wheels");
Console.WriteLine("Press F to Exit the vehicle");
char c = Convert.ToChar(Console.ReadLine());
switch (c)
{
case 'a':
{
car.wheel();
break;
}
case 'b':
{
car.doors();
break;
}
case 'c':
{
car.engine();
break;
}
case 'd':
{
car.oil();
break;
}
case 'e':
{
newmodel.newrims();
break;
}
case 'f':
{
Environment.Exit(0);
break;
}
default:
{
Console.WriteLine("Please Enter the Correct Input");
break;
}
}
}
}
}
}