正如你們可以從代碼中看到我創建三類汽車,新模型,主。所有的基本方法都是在車類中,我創建了繼承類來嘗試(繼承)。因爲你可以看到我在做什麼只是用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