instanceof 和类型转换

  1. 父类引用指向子类对象

  2. 把子类转换成父类,向上转型

  3. 吧父类转换成子类,向下转型:强制转换

  4. 方便方法的调用

封装 继承 多态

import Dome.Person;
import Dome.Student;
import Dome.Teacher;
?
public class Application {
  public static void main(String[] args) {
      Person obj = new Student();
      ((Student)obj).go();
  }
}
package Dome;
?
public class Teacher extends Person{
}
?
?
?
?
?
?
?
?
?
?
?
?
/*
public static void main(String[] args) {
?
          Object object = new Object();
          System.out.println(object instanceof Student);
          System.out.println(object instanceof Person);
          System.out.println(object instanceof Object);
          System.out.println(object instanceof Teacher);
          System.out.println(object instanceof String);
?
*/

instanceof 和类型转换

上一篇:ROS服务与客户端编写详解


下一篇:VLOOKUP逆向查找