正如你们可以从代码中看到我创建三类汽车,新模型,主。所有的基本方法都是在车类中,我创建了继承类来尝试(继承)。因为你可以看到我在做什么只是用newmodel继承类的newrims()方法输出car类的wheel()方法来创建一个完整的句子。需要使代码更准确的建议。替代或良好的方式,以防止类输出
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;
}
}
}
}
}
}
您正在寻找'base',而不是'car'。 – CodeCaster 2012-08-14 13:29:29
我很努力去理解你的实际问题...... – 2012-08-14 13:29:40
这也是你的功课吗?请尝试相应地添加标签 – sundar 2012-08-14 13:31:22