public class Driver { public static void main(String [] args) { Person regPerson = new Person(); Hero supPerson = new Hero(); // Instanceof checks if the object is a certain type or // a subclass of that type (e.g., a Hero is a Person) if (regPerson instanceof Person) System.out.println("regPerson is a type of Person"); if (supPerson instanceof Person) System.out.println("supPerson is also a type of Person"); // Object.getClass() checks if an object is an instance // of a specific class (excludes subclasses) System.out.println(regPerson.getClass().getName()); if (regPerson.getClass().getName() == "Person") System.out.println("regPerson is class Person"); if (supPerson.getClass().getName() == "Person") System.out.println("supPerson is class Person"); } }