+ 1
What is the output of this code? Why ?
class Month { public Month() { System.out.print("may"); } } public class program { public static void main(String[] args){ Month a = new Month(); boolean x1 = a instanceof Month; System.out.print(x1); } }
1 Answer
+ 2
Output is:
maytrue
The month class has print statement in the constructor, which prints may, and the cursor stays at that line. Next in the main method, an object is created (thus the constructor is called) and then you check is the object is an instance of Month class (which it is). so the Boolean is true, and you print it, in the same line.



