using System; using System.Collections.Generic; using System.Text; namespace Class { class Vehicle //定义车类的基础类 { public int Wheels; //公共成员 车轮数 protected float Weight; //保护成员 车重量 public void F() { Wheels = 4; Weight=2000.36f; } } class Train //定义火车类 { public int num; //车厢数目 private int passengers;//乘客数 private float Weight; //重量 public void F() { num = 20; passengers = 118; Vehicle V1 = new Vehicle(); V1.Wheels = 16; //公共成员 Weight = 6000.00f; } } class Car : Vehicle //继承类 { int Passengers; public void F() { Vehicle V1 = new Vehicle(); V1.Wheels = 4; Passengers = 6; //V1.Weight = 3000.00;//不可以访问保护成员 } } } using System; using System.Collections.Generic; using System.Text; namespace Class { class A { } class B { A a = new A(); //声明一个A的实例 void F() { A aa = new A();//在类B的方法F 中创建一个A的实例 } } class C:A{ //声明从A继承的类C } class Program { static void Main(string[] args) { Car c1 = new Car(); c1.Wheels = 5; //c1.Weight = 3000.00f; Console.WriteLine(c1.Wheels.ToString()); //Console.WriteLine(c1.Weight.ToString()); Console.ReadLine(); } } }