Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8744755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:53:36+00:00 2026-06-13T11:53:36+00:00

I am trying to learn about instanceof operator in java as per the link

  • 0

I am trying to learn about instanceof operator in java as per the link :- instanceof

But when i try to run their following 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));
}

}

class Parent {}
class Child extends Parent implements MyInterface {}
interface MyInterface {}

I get the following errors at compile time:

./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

Below is the directory structure where the src code is placed:-

-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

Note: I removed the interface implementation from Child.java and InstanceOfDemo.java to compile and run the code.

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:-

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:53:37+00:00Added an answer on June 13, 2026 at 11:53 am

    Your interface should also be in .java file so you need to put MyInterface in MyInterface.java

    -rw-rw-r-- 1 ankit ankit  25 Oct 25 15:20 MyInterface<---Rename it as 
                                                             MyInterface.java
    

    After this compile again and everything should work fine

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn about the Jini API in java, but can't get
I'm trying to learn about this feature of javascript I keep seeing in code,
I am currently trying to learn about OpenGL ES for the iPhone and following
I'm trying to learn about JAX-WS, specifically using WSDLs in Java. I want to
I am somewhat new to jQuery but have been having fun trying learn about
Trying to learn about php's arrays today. I have a set of arrays like
I'm trying learn more about RavenDB and at the moment to focus on how
I am trying to learn about the ScriptProperties object in GAS. I tried setting
I've been trying to learn about metaclasses in Python. I get the main idea,
I'm trying to learn about condition variables and how to use it in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.