The super Keyword


The super Keyword

In addition to its own nonstatic fields, a subclass must also ensure that any inherited nonstatic fields are initialized . This can be achieved by having a subclass constructor first scall a superclass constructor using the super keyword, followed by any arguments needed for the superclass constructor ”

 super(arguments); 

The superclass constructor call must be the first executable statement in the subclass constructor. If a superclass constructor is not explicitly called, the system will call the no-argument (default) superclass constructor. The super keyword can also be used to access superclass data or function members .

Example: Using the super Keyword

For an example of calling a superclass constructor, look at the IonizedSpecies class from the "Inheritance Basics" example earlier in this chapter. For an example of calling a superclass method, see the "Method Overriding" section of Chapter 9.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net