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'

Answer from sunil on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › core java › java instanceof operator
Java instanceof Operator | Baeldung
May 11, 2024 - We’ll also create a class Circle, which implements the Shape interface and also extends the Round class: public class Circle extends Round implements Shape { // implementation details } The instanceof result will be true if the object is an instance of the type:
Discussions

Java Interfaces Explained with Examples - Guide - The freeCodeCamp Forum
Interfaces Interface in Java is a bit like the Class, but with a significant difference : an interface can only have method signatures, fields and default methods. Since Java 8, you can also create default methods. Classes that implement an interface are thought to be signing a contract and ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
September 8, 2019
Can we create an instance of an interface in Java? - Stack Overflow
For you Android programmers, Google ... an inner interface here. 2016-08-10T15:06:29.073Z+00:00 ... Yes we can, "Anonymous classes enable you to make your code more concise. They enable you to declare and instantiate a class at the same time. They are like local classes except that they do not have a name"->>Java ... More on stackoverflow.com
🌐 stackoverflow.com
Can instanceOf operator be used to check if an object is an instance of a n interface, or type?
To add to what others have said already, there's a neat trick you can do in typescript to check if your instance is of a given "type". You declare it as an abstract class and implement the Symbol.hasInstance method. Example: abstract class Person { abstract readonly name: string; abstract readonly age: number; public static [Symbol.hasInstance](instance: unknown): instance is Person { if (instance === null || (typeof instance !== 'object' && !(instance instanceof Person))) return false; const name: unknown = (instance as any).name; const age: unknown = (instance as any).age; if (typeof name !== 'string' && !(name instanceof String)) return false; return typeof age === 'number' || age instanceof Number; } } Then you can use it as: const person = { name: "SomeName", age: 55 }; const noPerson = { weight: "300kg" }; console.log(person instanceof Person); // will print true console.log(noPerson instanceof Person); // will print false The advantage of this method in my opinion is that because typescript has a structure typing system, you can just do: class PersonImpl implements Person { constructor( readonly name: string, readonly age: number ) { } } console.log(new PersonImpl("SomeName", 55) instanceof Person); // will also print true This way, if you make a typo on PersonImpl you will know immediately that it's wrong and at runtime you can still type check. More on reddit.com
🌐 r/typescript
10
5
August 10, 2023
attitude towards casting in java
Personally, I'd say that you should avoid casting where possible. But keep in mind that especially when dealing with generics you shouldn't be afraid to use them, even in "unsafe" ways. Just check out Java's std lib: it's full of unchecked generic casts. There's a fine line between good design and the necessity to use casts normally, but when dealing with erasure there's really nothing you can do to avoid them in many circumstances More on reddit.com
🌐 r/java
47
5
March 19, 2023
🌐
Alvin Alexander
alvinalexander.com › java › java-instanceof-interface-example
Java instanceof interface example | alvinalexander.com
That’s the basic instanceof behavior — seeing if a reference is an instance of a particular class. The second line of output is printed because the dog reference is an instance of the Dog class, and the Dog class implements the Animal interface. This line of code, and the true value it returns, shows Java inheritance at work:
🌐
DataCamp
datacamp.com › doc › java › instanceof
instanceof Keyword in Java: Usage & Examples
The instanceof keyword in Java is a binary operator used to test whether an object is an instance of a specific class or implements a particular interface.
🌐
Programiz
programiz.com › java-programming › instanceof
Java instanceof (With Examples)
Here, d1 is an instance of Dog class. The instanceof operator checks if d1 is also an instance of the interface Animal. Note: In Java, all the classes are inherited from the Object class.
🌐
Medium
medium.com › @AlexanderObregon › how-javas-instanceof-operator-works-09071a27cd3b
How Java’s instanceof Operator Works | Medium
February 28, 2025 - The instanceof operator checks an object's type at runtime by examining its class hierarchy and implemented interfaces. It works efficiently with single inheritance by following a direct chain and processes interface checks by scanning all ...
🌐
Armedia
armedia.com › home › blog › “instanceof”, why and how to avoid it in code
Java “instanceOf”: Why And How To Avoid It In Code - Armedia
November 23, 2019 - The java “instanceof” operator is used to test whether the object is an instance of the specified type (class or subclass or interface). It is also known as type comparison operator because it compares the instance with type.
Find elsewhere
🌐
LabEx
labex.io › tutorials › java-how-to-check-if-an-object-implements-an-interface-in-java-560009
How to Check If an Object Implements an Interface in Java | LabEx
Learn how to check if an object implements an interface in Java using the `instanceof` keyword. Master runtime type checking, handling multiple interfaces, and null objects in this hands-on lab.
🌐
Jenkov
jenkov.com › tutorials › java › instanceof.html
Java instanceof operator
July 4, 2020 - The Java instanceof operator can determine whether a given object is an instance of a given class or interface. The Java instanceof operator was updated in Java 14 with pattern matching functionality, making it more concise to use.
🌐
GeeksforGeeks
geeksforgeeks.org › java › instanceof-keyword-in-java
instanceof Keyword in Java - GeeksforGeeks
July 23, 2025 - We can always first check for validity using instanceof, then do typecasting. ... // Java program to demonstrate that non-method // members are accessed according to reference // type (Unlike methods which are accessed according // to the referred object) class Parent { int value = 1000; } class Child extends Parent { int value = 10; } // Driver class class Test { public static void main(String[] args) { Parent cobj = new Child(); Parent par = cobj; // Using instanceof to make sure that par // is a valid reference before typecasting if (par instanceof Child) { System.out.println( "Value accessed through " + "parent reference with typecasting is " + ((Child)par).value); } } }
🌐
ArcGIS
desktop.arcgis.com › en › arcobjects › latest › java › 7c061b6b-7317-4d53-aa15-a9c0a43f278b.htm
Casting and runtime type checking (using instanceof)—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
This style of programming has the ... casting and coercing operation is used to convert between types and the instanceof operator is used to check for type information at run time....
🌐
Simplilearn
simplilearn.com › home › resources › software development › understanding the use of instanceof in java
Understanding the Use of Instanceof in Java with Examples
September 14, 2025 - Instanceof in java is a binary operator used to check if the specified object is an instance of a class, subclass, or interface. Learn all about it now!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Coderanch
coderanch.com › t › 626822 › certification › instanceof-operator-interface-class
instanceof operator with an interface versus class [Solved] (Associate Certification (OCAJP 8) forum at Coderanch)
January 12, 2014 - Thus anInteger instanceof Cloneable will also not compile But this example compiles without any problem: Reason why: the Number class is not final, so there could be a subclass that implements the Cloneable interface. That's also why (Cloneable) aNumber will compile (but will throw a ClassCastException at runtime).
🌐
freeCodeCamp
forum.freecodecamp.org › guide
Java Interfaces Explained with Examples - Guide - The freeCodeCamp Forum
September 8, 2019 - Interfaces Interface in Java is a bit like the Class, but with a significant difference : an interface can only have method signatures, fields and default methods. Since Java 8, you can also create default methods.
🌐
javaspring
javaspring.net › blog › java-is-instance-of
Mastering `instanceof` in Java: A Comprehensive Guide — javaspring.net
In Java, the `instanceof` operator is a powerful tool that allows developers to check whether an object is an instance of a particular class, interface, or their sub-types. It plays a crucial role in type checking, enabling more flexible and ...
🌐
W3Schools
w3schools.com › java › java_interface.asp
Java Interface
assert abstract boolean break byte ... if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Metho...
🌐
Java Development Journal
javadevjournal.com › home › java instanceof
Java instanceof | Java Development Journal
November 8, 2024 - The “instanceof” operator is a binary operator in Java that checks if an object is an instance of a particular class or interface. It returns a boolean value, showing whether the object is an instance of the specified class or interface.
🌐
How to do in Java
howtodoinjava.com › home › java object oriented programming › java instanceof operator
Java instanceof Operator - HowToDoInJava
January 3, 2023 - Java instanceof (type comparison operator) is used to test if a specified variable is an instance of the specified class or interface