The instanceof Keyword in Java


Use instanceof to test whether an object is an instance of a specific class or interface.

Source Code

class Animal {}
class Dog extends Animal {
    public static void main(String[] args) {
        Animal myDog = new Dog();
        System.out.println(myDog instanceof Animal); // true
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments