实现一个新的子类对象时会调用父类的构造器,(super())且这句话必须在子类的第一行
其中包含了
向上转型:Father father = new son();
父类的引用指向了子类实例。其中这个新类引用能够使用的方法主要时看左边的类型
向下转型:Son s1 = (Son)father;
该转换可以使用到instanceof函数;
这里必须使用强制转换才能进行向下转型。
instanceof使用方法
Person p1 = new Person(); Person p2 = new Man(); Man m1 = new Man(); System.out.println(p1 instanceof Man);//false System.out.println(p2 instanceof Man);//true System.out.println(m1 instanceof Man);//true