Question : check instance of java
Answered by : wissam-fawaz
// instanceof Checks whether object is instance of a given class
Object obj = new String("Hello World!");
// obj is instance of String and as such first msg is printed out
if(obj instanceof String) { System.out.println(obj + " is instance of String class"); // This msg is printed
} else { System.out.println(obj + " is not instance of String class");
}
Source : | Last Update : Sun, 27 Mar 22