关于BINDING的一个考试题,有兴趣可以试试
要期末考试了,今天在家复习。这是我期中考试的一道题,关于BINDING的。有兴趣的朋友可以试试。过几天我发答案上来。
程序代码:
public class GrandParent{ public GrandParent(){} public double giveMoney(Parent p){ if(p instanceof Child){ amount = 15.5; else amount = 515.5; return amount; } public class Parent extends GrandParent{ public Parent(){} public int takePicture(Object o){ return 314; } public int takePicture(Parent p){ return 414; } } public class Child extends Parent{ public int takePicture(Parent p){ return 514; } public int takePicture(Child c){ return 614; } }
有如下:
Child child1 = new Child(); Parent parent1 = new Parent(); Parent parent2 = new Child(); Grandparent grandpa = new Parent();
问题:
1 System.out.println(child1.takePicture(grandpa)); 2 System.out.println(grandpa.giveMoney(parent2)); 3 System.out.println(grandpa.takePicture(child1)); 4 System.out.println(parent2.takePicture(child1));