title: Errors in using instanceof operator with an interface?
body: <p>I am trying to learn about <code>instanceof</code> operator in java as per the link :- <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/examples/InstanceofDemo.java" rel="nofollow">instanceof</a></p>
  
  <p>But when i try to run their following code:- </p>
  
  <pre><code>class InstanceofDemo {
  public static void main(String[] args) {
  
      Parent obj1 = new Parent();
      Parent obj2 = new Child();
  
      System.out.println("obj1 instanceof Parent: "
          + (obj1 instanceof Parent));
      System.out.println("obj1 instanceof Child: "
          + (obj1 instanceof Child));
      System.out.println("obj1 instanceof MyInterface: "
          + (obj1 instanceof MyInterface));
      System.out.println("obj2 instanceof Parent: "
          + (obj2 instanceof Parent));
      System.out.println("obj2 instanceof Child: "
          + (obj2 instanceof Child));
      System.out.println("obj2 instanceof MyInterface: "
          + (obj2 instanceof MyInterface));
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>class Parent {}
  class Child extends Parent implements MyInterface {}
  interface MyInterface {}
  </code></pre>
  
  <p>I get the following errors at compile time:</p>
  
  <pre><code>./Child.java:1: error: cannot find symbol
  class Child extends Parent implements MyInterface{
                                        ^
    symbol: class MyInterface
  InstanceOfDemo.java:9: error: cannot find symbol
  System.out.println("obj1 instanceOf MyInterface" + (obj1 instanceof MyInterface));
                                                                      ^
    symbol:   class MyInterface
    location: class InstanceOfDemo
  InstanceOfDemo.java:12: error: cannot find symbol
  System.out.println("obj1 instanceOf MyInterface" + (obj2 instanceof MyInterface ));
                                                                      ^
    symbol:   class MyInterface
    location: class InstanceOfDemo
  3 errors
  </code></pre>
  
  <p>Below is the directory structure where the src code is placed:-</p>
  
  <pre><code>-rw-rw-r-- 1 ankit ankit 174 Oct 25 15:36 Child.class
  -rw-rw-r-- 1 ankit ankit  31 Oct 25 15:36 Child.java
  -rw-rw-r-- 1 ankit ankit 920 Oct 25 15:41 InstanceOfDemo.class
  -rw-rw-r-- 1 ankit ankit 637 Oct 25 15:41 InstanceOfDemo.java
  -rw-rw-r-- 1 ankit ankit  25 Oct 25 15:20 MyInterface
  -rw-rw-r-- 1 ankit ankit 186 Oct 25 15:36 Parent.class
  -rw-rw-r-- 1 ankit ankit  16 Oct 25 15:18 Parent.java
  </code></pre>
  
  <p>Note: I removed the interface implementation from <code>Child.java</code> and <code>InstanceOfDemo.java</code> to compile and run the code.</p>
  
  <p>Edit 1:- can i consider that instanceof operator can't be used with Interfaces because the definiton of instanceof operator as per Oracle is as follows:-</p>
  
  <blockquote>
    <p>The instanceof operator compares an object to a specified type. You can use it to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface.</p>
  </blockquote>