here is the question: Which of the following statements are true? 1) static methods do not have access to the implicit variable called this 2) A static method may be called without creating an instance of its class 3) A static method may not be overriden to be non-static 4) A static method may not be overloaded i think ans may be 2) and 3) , but the correct ans is 1),2) and 3) , could somobody here explain this? i think snippet below is correct: static int i; static int method(){ return this.i; } so why 1) is true?
Tony Sam<BR>One want to be a SCJP...
Simeon Shi
Ranch Hand
Joined: Dec 09, 2001
Posts: 35
posted
0
hi,Tony... have u ever tried the snippet? the compiler will also complain "non-static variable this cannot be referenced from a static context". just like a static class which can be referred without the instance of itself,a static method can also be called without the instance of the class containing it.so...a static method is not "bound" to the class.so,the "this" could not be used coz of this specific.
Vikrama Sanjeeva
Ranch Hand
Joined: Sep 02, 2001
Posts: 756
posted
0
Originally posted by Tony Sam: here is the question: Which of the following statements are true? 1) static methods do not have access to the implicit variable called this 2) A static method may be called without creating an instance of its class 3) A static method may not be overriden to be non-static 4) A static method may not be overloaded i think ans may be 2) and 3) , but the correct ans is 1),2) and 3) , could somobody here explain this? i think snippet below is correct: static int i; static int method(){ return this.i; } so why 1) is true?
Yes 1,2,3 are true For confirmation you may try this code
Bye. Viki.
------------------ Count the flowers of ur garden,NOT the leafs which falls away!