例如:
package k; public class Animal { public int age=10; public Animal(){ System.out.println("animal class is running"); } }
package k; public class Dog extends Animal { public Dog(){ System.out.println("dog class is running"); } }
package k; public class HelloWorld { public static void main(String[] args){ Dog dog=new Dog(); System.out.println(dog); } }
结果:
animal class is running dog class is running k.Dog@1db9742
打印dog对象时有那么多方法不用,为什么只打印了toString()
Raelovejava
KevinHY
笑揽清溪月
大咪
相关分类