Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
You can think of instance of as a comparison operator in which it compares object Types (including its parent Types). Object Type == Object Type class Animal {} class Dog extends Animal {} Animal a = new Animal(); Dog d = new Dog(); if(a instanceof Animal) // true System.out.println("a is an Animal"); if(d instanceof Dog) // true System.out.println("d is a Dog"); if(d instanceof Animal) // true System.out.println("d is also an Animal"); if(a instanceof Dog) // false System.out.println("a is not a Dog"); https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html
16th Jul 2017, 8:43 PM
ChaoticDawg
ChaoticDawg - avatar