| Author |
Super Inside the Static
|
Micheal John
Ranch Hand
Joined: Nov 01, 2006
Posts: 344
|
|
FROM web page Whether super can be used inside the static methos? Anserr given in the site: [/CODE] The keyword, this, refers to the instance on which the method has been invoked. A static method--also known as a class method-- is not invoked on a particular instance of an object, but is instead invoked on the class. Since a static method is not associated with a particular instance, an attempt to use the keyword, this, within the body of a static method results in a Compile-time error. Similarly, the keyword, super, can not be used within the body of a static method. [/CODE]
|
Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
|
 |
Arpit Khandelwal
Greenhorn
Joined: Dec 11, 2006
Posts: 10
|
|
No you can not use super in a static context. just to prove this point , try the following code :: class base { static void f1(){ System.out.print("base"); } } class test extends base { static void f2(){ ------>super.f1(); System.out.print("base"); } public static void main(String args[]) { test.f2(); } } the compiler would complain "non-static variable super can not be referenced from a static context"
|
-Arpit Khandelwal<br />"impossible" itself says i m possible!
|
 |
Nomula vasudevu
Ranch Hand
Joined: Oct 25, 2006
Posts: 107
|
|
|
static methods cann't be overriden. Then how can we use super keyword. Therefore the option static methods may use super keyword is not true. Am I correct ?
|
 |
 |
|
|
subject: Super Inside the Static
|
|
|