【发布时间】:2019-01-25 10:19:08
【问题描述】:
问题:我有一个以这种形式创建的对象:
Animal temporalAnimal = new Dog("Dog", "Ace","Boxer");
//Type //Name //Race
Animal 是基类,Dog 是子类。 Type 和 Name 来自于 Animal,Race 来自于 Dog 类。我想将 temporalAnimal 中“Race”的值更改为“Shiba Inu”,但我无法访问该属性(它在子类上是公共的),我该如何修改他的值?
string type;
public string Type
{
get { return type; }
set { type = value; }
}
【问题讨论】:
-
构造函数的代码在哪里?
标签: c# oop inheritance properties subclass