Page 208 - AP Computer Science A, 7th edition
P. 208
NOTE
1. If super is used in the implementation of a subclass
constructor, it must be used in the first line of the constructor
body .
2. If no constructor is provided in a subclass, the compiler
provides the following default constructor:
public SubClass() {
super(); //calls default constructor
of superclass }
• A subclass
• A subclass
• A subclass
• A subclass
• A subclass superclass.
• A subclass
Rules f or Subclasses
can add new private instance variables.
can add new public, private, or static methods. can override inherited methods.
may not redefine a public method as private. may not override static methods of the
should define its own constructors.
cannot directly access the private members of
• A subclass
its superclass. It must use accessor or mutator methods.
Declaring Subclass Objects
When a superclass object is declared in a client program, that reference can refer not only to an object of the superclass, but also to objects of any of its subclasses. Thus, each of the following is legal: