another version of this code that doesn't work to : public static void haveFun(Person person) { if(person instanceof Player){ person.play(); } else if(person instanceof Dancer){ person.dance(); } here I have another version of method haveFun: public static void haveFun(Person person) { try { if(person instanceof Player){ person.play(); } }catch (Exception e){ person.dance(); } }