⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8-1.txt

📁 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告 C#实验报告
💻 TXT
字号:
using System;
class Vehichle//定义汽车类
{
          public       int wheels;                   //公有成员;轮子个数
          protected  float weight;                //保护成员:重量

          public       Vehicle(){;}

          public       Vehicle( int w,float g ) 
         {
                          wheels = w;
                          weight = g;
          }
          public void Show() {
                    Console.WriteLine("the wheel of vehicle is : {0}", wheels);
                    Console.WriteLine("the weight of vehicle is : {0}",weight);
          }
}
class train    //定义火车类
{
          public int num;    //公有成员;车厢数目
          private int passengers;   //私有成员;乘客数
          private float weight;       //私有成员;重量
          public Train() {;}
          public Train ( int n, int p, float w) {
                 num =n;
                 passengers = p;
                 weight = w;
          }
          public void Show() {
                 Console.WriteLine ( "the num of train is : {0}", num );
                 Console.WriteLine ( "the weight of train is : {0}", weight);
                 Console.WriteLine ( "the Passengers train car is : {0}", Passengers);
          }
} 
class Car:Vehichle   //定义轿车类
{
          int passengers;          //私有成员;乘客数
          public Car (int w, float g, int p) :  base ( w, g )
          {
                  wheels = w;
                  weight = g;
                  passengers = p;
          }
          new public void Show() {
                   Console.WriteLine( "the wheel of car is:{0}", wheels);
                   Console.WriteLine( "the weight of car is:{0}", weight);
                   Console.WriteLine( "the Passengers of car is:{0}", Passengers);
          }
}
class Test
{
          public static void Main() {
                   Vehicle v1 = new Vehicle(4,5);
                   Train t1 = new Train();
                   Train t2 = new Train(10,100,100);
                   Car c1 = new Car(4,2,4);
                   V1.show();
                   t1.show();
                   t2.show();
                   c1.show();
         }
}

程序的运行结果为:
the wheel of vehicle is : 0
the weight of vehicle is : 0
the num of train is : 0
the weight of train is : 0
the Passengers of train is : 0
the num of train is : 10
the weight of train is : 100
the Passengers of train is :100
the wheel of car is : 4
the weight of car is : 2
the Passengers of car is : 4

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -