use of instanceof in java code example
Example 1: instanceof java
class Example{
public static void main(String args[]){
Example anexample=new Example();
System.out.println(anexample instanceof Example);
}
}
Example 2: insanceof
The instanceof operator tests to see if the prototype property of a constructor
appears anywhere in the prototype chain of an object. The return value is a
boolean value.
For example :-
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
const auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car);
console.log(auto instanceof Object);