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 8860891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:21:57+00:00 2026-06-14T15:21:57+00:00

instanceof can be used to test if an object is a direct or descended

  • 0

instanceof can be used to test if an object is a direct or descended instance of a given class. instanceof can also be used with interfaces even though interfaces can’t be instantiated like classes. Can anyone explain how instanceof works?

  • 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-14T15:21:59+00:00Added an answer on June 14, 2026 at 3:21 pm

    First of all, we can store instances of classes that implements a particular interface in an interface reference variable like this.

    package com.test;
    
    public class Test implements Testable {
    
        public static void main(String[] args) {
    
            Testable testable = new Test();
    
            // OR
    
            Test test = new Test();
    
            if (testeable instanceof Testable)
                System.out.println("instanceof succeeded");
            if (test instanceof Testable)
                System.out.println("instanceof succeeded");
        }
    }
    
    interface Testable {
    
    }
    

    ie, any runtime instance that implements a particular interface will pass the instanceof test

    EDIT

    and the output

    instanceof succeeded
    instanceof succeeded
    

    @RohitJain

    You can create instances of interfaces by using anonymous inner classes like this

    Runnable runnable = new Runnable() {
        
        public void run() {
            System.out.println("inside run");
        }
    };
    

    and you test the instance is of type interface, using instanceof operator like this

    System.out.println(runnable instanceof Runnable);
    

    and the result is ‘true’

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

Sidebar

Related Questions

How can I code to share the same instance of a singletonic class among
Can we able to create two instance of log4j in class one to write
can anyone explain to me what is happening when a instance of a class
Is a new (or different) instance of TestCase object is used to run each
I understand the need to test a class that has logic (for instance, one
The question is how can I test the fact that object disposes resources when
I was wondering, why AnyVal can not be used in an isInstanceOf check ?
The instanceof keyword in JavaScript can be quite confusing when it is first encountered,
Only one instance of a ScriptManager can be added to the page. this error
Can we have multiple instance of a Service in Android ? I want 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.