What is the output from the following code
class Employee { private String name = "Unknown"; public void setName(String name) { this.name = name; } public String getName() { return name; } } public class Main { public static void main(String[] args) { String str = "test"; if (str instanceof Employee) { System.out.println("Employee"); }else{ System.out.println("Not"); } } }
if (str instanceof Employee) { // A compile-time error System.out.println("Employee"); }else{ System.out.println("Not"); }
The use of the instanceof operator will generate a compiler error because the String class is not in the inheritance-chain of the Employee class.