Java多态性应用——多态数组、多态参数

多态数组:数组

Person[] person = {new Person("张三", 32),
                                  new Student("李四", 21, 120, 90.0),
                                  new Student("王五", 22, 119, 91.5),
                                  new Teacher("刘老师", 35, 10, "Java EE"),
                                  new Teacher("张老师", 11)};

多态参数——方法参数列表中的引用类型参数spa

public static void method(Person p) {//形参
        System.out.println(p.say());
}
// 调用此方法:
Student s = new Student();
xxx.method(s);
相关文章
相关标签/搜索