aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Super Inside the Static Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Super Inside the Static" Watch "Super Inside the Static" New topic
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 ?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Super Inside the Static
 
Similar Threads
Instance Variables
Dan Chisholm Chapter 4, question 15
use of super,this in static method
my notes on JLS for any1 who needs them !!
does static methods inherit ? what about private ?