posted 12 years ago
i would like mention there are two thing to notice
1. Up-casting of object references
a sub-class object can be treated as a super-class object .In give problem Dog ,Cat and Bird object references are up-casted to a Animal object . Therefore in follwing method one can pass object of type Animal or any subtype of Animal
2. Method resolution
it is the object at run-time determines whose checkup() is called not the reference type. In this case reference type is always of Animal type and object at run time can be of type Animal and its sub-types(Dog , Cat and Bird). Just before excuting the method the compiler dermines the object type of a and calls method of that class
there is a one trick if Dog extends Animal and Animal has no checkup() , then there will be a error.
So super type must have the method which can is called on its sub types.