+ 1
What is the output of the code?
class Test{ public static void main(String[] args){ System.out.print(this); } }
2 Answers
+ 8
Error. It would not output "this" because "this" is not defined as a string by using "". If test were a variable (which no variable was initialized) then it would print the value contained in that variable. You either need to initialize it as a variable or use quotation marks to specify that it is text that should be printed.
+ 2
Actually u get compile error:
non-static variable this cannot be referenced from a static context
System.out.print(this);
^
1 error
'this' is a key word reference to the current object.
As Compiler error message shows u can't call non static method/variable in static method.