Q. Consider the following classes: public class Test { public static void test() { this.print(); } public static void print() { System.out.println("Test"); } public static void main(String args []) { test(); } } What is the result of compiling and running this class? A.The string Test is printed to the standard out. B.A runtime exception is raised stating that an object has not been created. C.Nothing is printed to the standard output. D.An exception is raised stating that the method test cannot be found. E.An exception is raised stating that the variable this can only be used within an instance. F.The class fails to compile stating that the variable this is undefined. ************ given answer is F.but I cann't know it clearly.if you think the answer is right,please explain it to me in detail.thanks for your reply!
Dream first and Do later
fengqiao cao
Ranch Hand
Joined: Oct 26, 2001
Posts: 71
posted
0
hi, there i think the answer is not right. because "this" is always refered to a certain object. so it meas it can not be refered within a static context. any commment?
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
Hi, the given answer is clearly wrong. The correct answer is E since you can't reference this within a static context. HIH ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform