Sullivan Market

a web based full-circle development system



My Java Tutorials - The 'Super' Keyword

Keywords -- The 'Super' Keyword:
    The super keyword, somewhat like the 'this' keyword, is a placeholder for the class's superclass. You can use it anywhere that you use 'this, but 'super' refers to the superclass rather than the current object.

For Example...

1 import java.awt.Point
2
3 class NamedPoint extends Point {
4 String name;
5
6 NamedPoint(int x, int y, String name) {
7 super(x,y);
8 this.name = name;
9 }
10
11 public static void main(String[] arguments) {
12 NamedPoint np = new NamedPoint(5, 5, "SmallPoint");
13 System.out.println("x is " + np.x);
14 System.out.println("y is " + np.y);
15 System.out.println("Name is " + np.name);
16 }
17 }

Back To Java Tutorials

©2012 SullivanMarket.com