package com.thinkinjava.polymorphism.misc;

class Useful {
    public void f() { System.out.println("Userful.f()"); }
    public void g() { System.out.println("Userful.g()"); }
}

class MoreUseful extends Useful {
    public void f() { System.out.println("MoreUserful.f()"); }
    public void g() { System.out.println("MoreUserful.g()"); }
    public void h() { System.out.println("MoreUserful.h()"); }
    public void j() { System.out.println("MoreUserful.j()"); }
    public void k() { System.out.println("MoreUserful.k()"); }
}

public class RTTI {
    public static void main(String[] args) {
        Useful[] x = {
            new Useful(),
            new MoreUseful(),
        };
        x[0].f();
        x[1].g();
        // Compile time: method not found in Useful;
        // x[1].h();
        ((MoreUseful)x[1]).h();
        ((MoreUseful)x[1]).g();
        ((MoreUseful)x[0]).g();  // ClassCastException
        ((MoreUseful)x[0]).h();  // ClassCastException
    }

}
