C#子类为什么改不了父类变量的值
展开全部
输出结果对的啊:你仔细看,有4,,2,4的:
根据我的编程经验来看。
不能用new,new是重新创建一个和父类完全一样名字的函数,但是不会重写。
这样修改:class vehicle{……
public virtual void show(){Console.WriteLine("the wheel of vehicle is :{0}", wheels);
Console.WriteLine("the weight of vehicle is :{0}", weight);}子类:class car : vehicle{………………
public overridevoid show(){Console.WriteLine("the wheel of car is:{0}", wheels);
根据我的编程经验来看。
不能用new,new是重新创建一个和父类完全一样名字的函数,但是不会重写。
这样修改:class vehicle{……
public virtual void show(){Console.WriteLine("the wheel of vehicle is :{0}", wheels);
Console.WriteLine("the weight of vehicle is :{0}", weight);}子类:class car : vehicle{………………
public overridevoid show(){Console.WriteLine("the wheel of car is:{0}", wheels);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询