Specifications

Sun Services
Java™ Programming Language
Module 6, slide 20 of 43
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
The instanceof Operator
public class Employee extends Object
public class Manager extends Employee
public class Engineer extends Employee
----------------------------------------
public void doSomething(Employee e) {
if ( e instanceof Manager ) {
// Process a Manager
} else if ( e instanceof Engineer ) {
// Process an Engineer
} else {
// Process any other type of Employee
}
}