非Animal呢?为何不写个万用类
/*4.非Animal呢?为何不写个万用类
* 类Object是JAVA里多有类的源头/父类*/
1 import java.util.*; 2 class Animalb{ 3 String name; 4 void eat(){ 5 System.out.println("动物在吃东西啦"); 6 } 7 } 8 class Doga extends Animalb{} 9 class Cata extends Animalb{} 10 11 public class FourFei { 12 public static void main(String[] args){ 13 Doga a = new Doga(); 14 Cata c = new Cata(); 15 16 ArrayList<Object> list = new ArrayList<Object>(); 17 list.add(a); 18 list.add(c); 19 20 if(a.equals(c)){ //判断两个对象是否相等 21 System.out.println("true"); 22 }else{ 23 System.out.println("false"); 24 } 25 System.out.println(c.equals(a)); 26 System.out.println(c.getClass()); 27 System.out.println(c.hashCode()); 28 System.out.println(c.toString()); 29 30 } 31 }