创建继承类的对象

时间:2017-08-02 17:55:18

标签: c# oop

什么是用一个词来调用的?

public class person
{
}
public class person1 : person
{
}
public class person2 : person
{
}

我已经阅读过这个代码,它创建了另一个继承类的新对象,但是在单个单词中调用了什么

person p=new person2();
person p1=new person1();

1 个答案:

答案 0 :(得分:8)

我认为您正在寻找的词是多态。但你的例子是错误的:

如果你这样说,那将是多态的:

let arrayLetters = ["a", "b", "c", "d", "e", "f", "g", "h", "i"] let arrayRemoveLetters = ["a", "e", "g", "h"] let arrayRemainingLetters = arrayLetters.filter { !arrayRemoveLetters.contains($0) } print(arrayRemainingLetters) //result - ["b", "c", "d", "f", "i"] 要么 person myPerson = new person1();

但是,您不能拥有与您的示例中相同的基类的两个类。

person myPerson = new person2();

虽然它们都是真的,但它们都继承了相同的基类,但它们并不相同。用真正的词语来表达:

假设你有一个班级person2 myPerson = new person1();。然后你有另外两个类VehicleCar。你能说BusBus吗?当然是。但是不能VehicleBus