super keyword

Syntax

>>-super-(-+--------------+-)-;-><
           '-ArgumentList-'

>>-super-.-Identifier-;-><

Description
The first statement of a constructor body may be an explicit invocation of a constructor of the direct superclass, written as super followed by a parenthesized argument list.

Suppose that a field access expression super.aName appears within class C, and the immediate superclass of C is class S. Then super.aName is treated exactly as if it had been the expression ((S)this).aName; thus, it refers to the field named aName of the current object, but with the current object viewed as an instance of the superclass. Thus it can access the field named name that is visible in class S, even if that field is hidden by a declaration of a field named name in class C.

If the keyword super occurs in an initialization expression for a field of an interface, a compilation error occurs.

Example
The use of super is demonstrated by the following example:

interface I { int x = 0; }
class T1 implements I { int x = 1; }
class T2 extends T1 { int x = 2; }
class T3 extends T2 {
    int x = 3;
    void test() {
        System.out.println("x=\t\t"+x);
        System.out.println("super.x=\t\t"+super.x);
        System.out.println("((T2)this).x=\t"+((T2)this).x);
        System.out.println("((T1)this).x=\t"+((T1)this).x);
        System.out.println("((I)this).x=\t"+((I)this).x);
    }

    public static void main(String[] args) {
        new T3().test();
    }
}

The above example produces the following output:

x=                  3
super.x=            2
((T2)this).x=       2
((T1)this).x=       1
((I)this).x=        0

Within class T3, the expression super.x is treated exactly as if it were:

((T2)this).x 

ngrelr.gif (548 bytes)
Syntax diagrams
Class constructors
class keywords

Source: The Java Language Specification. Copyright (C) 1996 Sun Microsystems, Inc.