- class TestMore
- {
- public static void main(String [] args)
- {
- Child c =new Child();
- System.out.println(c instanceof Father);[color=Red]//返回true,子类的对象属于父类的对象[/color]
- System.out.println(c instanceof Child);//返回true
- Father f =new Child();
- System.out.println(f instanceof Father);//返回true
- System.out.println(f instanceof Child);//返回true
- Father ff =new Father();
- System.out.println(ff instanceof Father);
- System.out.println(ff instanceof Child); [color=Red]//false,父类的对象不属于子类的对象[/color]
-
- }
- }
- class Father
- {
- }
- class Child extends Father
- {
- }
复制代码 |
|