// InstanceofOperatorTests.java Copyright (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2005-05-22 File created. // 2005-05-22 Last modification. // Testing operator instanceof import java.util.* ; class TestClass implements Cloneable { static int object_counter = 0 ; int object_number ; public TestClass() { object_counter ++ ; object_number = object_counter ; } public void make_speak() { System.out.print( "\n Hi! I'm object number " + object_number ) ; } } class DerivedClass extends TestClass { } class InstanceofOperatorTests { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; TestClass some_test_object = new TestClass() ; DerivedClass some_derived_class_object = new DerivedClass() ; System.out.print( "\n some_test_object instanceof Testclass returns " + ( some_test_object instanceof TestClass ) + "\n some_derived_class_object instanceof TestClass returns " + ( some_derived_class_object instanceof TestClass ) + "\n some_test_object instanceof DerivedClass returns " + ( some_test_object instanceof DerivedClass ) + "\n some_test_object instanceof Cloneable returns " + ( some_test_object instanceof Cloneable ) + "\n some_test_object instanceof Comparable returns " + ( some_test_object instanceof Comparable ) ) ; } }