Object test = null; Typo k = null; test = Start.run(str3); try{ if(test != null && test instanceof Typo){ System.out.println(test.getClass().getName()); k = (Typo) test; k.run(str3); } }catch(Exception ex){ ex.printStackTrace(); }