Java Reference
In-Depth Information
to access a static member then, as with instance fields, static members
are always accessed based on the declared type of the reference, not
the type of the object referred to.
3.3.6. The super Keyword
The super keyword is available in all non-static methods of a class. In
field access and method invocation, super acts as a reference to the cur-
rent object as an instance of its superclass. Using super is the only case
in which the type of the reference governs selection of the method im-
plementation to be used. An invocation of super. method always uses the
implementation of method the superclass defines (or inherits). It does
not use any overriding implementation of that method further down the
class hierarchy. Here is an example that shows super in action:
class Base {
/** return the class name */
protected String name() {
return "Base";
}
}
class More extends Base {
protected String name() {
return "More";
}
protected void printName() {
Base sref = (Base) this;
System.out.println("this.name() = " + this.name());
System.out.println("sref.name() = " + sref.name());
System.out.println("super.name() = " +
super.name());
}
}
 
Search WWH ::




Custom Search