就类变量而言,上抛和下铸有什么区别?
class Animal { public void callme() { System.out.println("In callme of Animal"); }}class Dog extends Animal { public void callme() { System.out.println("In callme of Dog"); } public void callme2() { System.out.println("In callme2 of Dog"); }}public class UseAnimlas { public static void main (String [] args) { Dog d = new Dog(); Animal a = (Animal)d; d.callme(); a.callme(); ((Dog) a).callme2(); }}
慕斯王
相关分类