I'm talking java language.
Variable "this", when used inside a class, refers to the current instance of that class, which means you cannot use "this" inside a static method.
But "super", when used inside a class, refers to the superclass of that class, not an instance of the superclass, which should mean that you can use "super" inside a static method. But it turns out you cannot.
A possible explanation would be to say that "super" also refers to an instance of the superclass, but I can't see why it should...
You can't use
super
from a static context for the same reason you can't usethis
in a static context. In both cases, the word refers to an instance.In a static context, you can always use the name of the superclass explicitly:
No,
super
does refer to an instance -- the same instance thatthis
refers to -- the current object. It's just a way to reference methods and fields in defined in the superclass that are overridden or hidden in the current class.Here is the section in the JLS about the
super
keyword:http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.11.2
In both cases, it is clear that an instance object is needed.
Also, a static context is somewhat different from an instance context, as a class can't override static methods, only hide them.
Super is a non static variable and non static entity cannot be accessed from static context.