Java学习
多态
多态是方法的多态,属性没有多态 父类和子类,有联系 类型转换异常!ClassCastException(类型转化异常) 存在条件:继承关系,方法需要重写,父类引用指向子类对象! Father f1 = new Son ();
static 方法:属于类,不属于实例 final 常量; private 方法;
instanceof (类型转换) 引用类型 判断一个对象是什么类型
public static void main ( String[ ] args) {
Object object = new Student ( ) ;
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 ) ;
System. out. println ( "=========================" ) ;
Person person = new Student ( ) ;
System. out. println ( person instanceof Student ) ;
System. out. println ( person instanceof Person ) ;
System. out. println ( person instanceof Object ) ;
System. out. println ( person instanceof Teacher ) ;
System. out. println ( "====================" ) ;
Student student = new Student ( ) ;
System. out. println ( student instanceof Student ) ;
System. out. println ( student instanceof Person ) ;
System. out. println ( student instanceof Object ) ;
}