The Department of Computer Science & Engineering |
STUART C. SHAPIRO: CSE
115 C
|
A class extends its superclass.
Inheritance: a (child) subclass inherits attributes and behaviors
from its (parent) superclass, its superclass, etc., and it specializes
them.
The superclass generalizes its subclasses.
A class may extend only one superclass. (No multiple inheritance.)
is-a: A dog is-a mammal, a mammal is-a vertebrate.
A superclass is abstract if it has at least one abstract
method.
An abstract method has no body (not even an empty body).
abstract public void move();
This requires every subclass to have this method.
A class with no abstract methods is concrete.
Only concrete classes may have instances.
super(args);
: Call to the parent class's
constructor.
Must be the first statement of the child's constructor.
If missing, Java compiler will insert super();
May have multiple methods (esp. constructors) with same name, but different signatures. Compiler will arrange for a call to the matching one.
this
: The current instance.
Additional access modifier:
private: accessible only to class within which it's declared.
protected: accessible to class within which it's declared, and all
subclasses (and every class in package).
public: accessible to every class.
See Inheritance demonstration and its documentation.