多态数组:

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)};

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

public static void method(Person p) {//形参
        System.out.println(p.say());
}
// 调用此方法:
Student s = new Student();
xxx.method(s);

 

相关文章:

  • 2022-01-08
  • 2021-08-04
  • 2021-12-09
  • 2022-01-15
  • 2021-10-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-09-18
  • 2022-12-23
  • 2021-10-11
相关资源
相似解决方案