public class Downcasting1 { public static void main(String[] args) { BankAccount x; // x is a Base class variable CheckingAccount y; // y and z are Derived class variables CheckingAccount z; /* ------------------------------------------------------- Remember that: A derived class may have MORE variables/methods than the base class ! ------------------------------------------------------- */ /* -------------------------------- A legal downcasting scenario -------------------------------- */ y = new CheckingAccount(343, "John", 2000.0); x = y; // Upcasting, allowed (discussed before wby) // x references a CheckingAccount object z = (CheckingAccount) x; // Downcasting, allowed because: // x references a CheckingAccount object // z is a CheckingAccount reference var. // compatible } }