/Users/lyon/j4p/src/collections/getclass/Child.java

1    /* 
2     * Child.java 
3     * 
4     * Created on December 3, 2002 
5     */ 
6     
7    package collections.getclass; 
8     
9    /** 
10    * Derived class with equals method Not overridden, 
11    * overridden using instanceof, overridden using getClass. 
12    * @author  Thomas Rowland 
13    */ 
14   public class Child extends Parent { 
15    
16       private static int id = 1; 
17    
18       /** 
19        * Overridden equals method using instanceof 
20        * instead of getClass. 
21        */ 
22       /* 
23        public boolean equals (Object o) { 
24           //if (o.getClass() == this.getClass() 
25           if (o instanceof Child) 
26               return (((Child)o).getId() == this.getId()); 
27           return false; 
28       } 
29       */ 
30    
31       public String toString() { 
32           return "I am a Child"; 
33       } 
34    
35       public int getId() { 
36           return this.id; 
37       } 
38   } 
39