Archive

Posts Tagged ‘upcasting’

Casting Reference Variables- Downcasting, Upcasting

Let us consider two classes class Animal, a more generic class and class Cat, a more specific class i.e a more specific animal. Let us settle for simple definitions for both the classes so as to get the concept right.

/*
The definition for more generic class Animal
Notice the eat() method, which will be inherited by all Classes extending Animal
*/

class Animal
{

public void eat()
{

System.out.println(“Animal  Eating“);

}

} Read more…