2.4 Superclasses

Another directive in the header is the .super directive which is used to indicate the superclass of the class. Every class must have a superclass; if no .super directive is given, java/lang/Object is assumed. The class java/lang/Object is special, because it doesn't have a superclass.

If you have

 .class Bicycle .super Vehicle 

then we say that Vehicle is a superclass of Bicycle, and Bicycle is a subclass of Vehicle.

An instance of class inherits all the fields and all the methods of the superclass. The idea is that you can use an instance of a subclass anywhere you can use an instance of the superclass. This behavior is discussed in more detail in section 4.2.2.



Programming for the Java Virtual Machine
Programming for the Javaв„ў Virtual Machine
ISBN: 0201309726
EAN: 2147483647
Year: 1998
Pages: 158
Authors: Joshua Engel

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