Summary 7
Summary 7
-
A subclass inherits the public variables and methods of the superclass, and has access to the public constructors of the superclass.
- Superclasses have no access to the methods of their subclasses; subclasses have no direct access to private variables of their superclasses.
- To write a subclass, we must include the keyword
extendsand the name of the class we are extending in the class definition.public class Subby extends TheSuper { } - The keyword
thisis used to call methods - both inherited and native - of the current instance of a class. - A method in the subclass which has the same name as a method of the superclass, overrides the superclass method.
- The keyword
superis used to access a method of the superclass:super.aMethod() //calls a superclass method - The syntax
super(arguments)is used to call a constructor of the superclass. This call must be the first line of code in a subclass constructor. - Javadoc will correctly generate documentation for a superclass and its subclasses if all the required files are placed in the same folder in which javadoc is called.
- If more than one constructor is present in the same class, the constructor is overloaded. Overloaded constructors must carry different parameters, or a different number of parameters if the data type of the parameters is the same.
- Methods are overloaded in a class by giving them the same name, but a different number or type of parameter(s). Merely a different return data type is not sufficient to overload a method, and is not legal.
- The
Math.random()method is used to generate random numbers. - The
System.out.print()method prints to the current line in the console.
© G. Hearn, & University of the Western Cape, 2006
Copyright 2007-2008,
by the Contributing Authors.
Cite/attribute Resource.
Summary 7. (2008, July 16). Retrieved May 21, 2013, from UWC Free Courseware Web site: http://freecourseware.uwc.ac.za/freecourseware/information-systems/java-platform-introduction/summarys/summary-7.
This work is licensed under a
Creative Commons License : Attribution-ShareAlike 3.0.






