Lecture 14 - Inheritance

Lecture 14 - Inheritance - The extends Keyword Is used to...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
The extends Keyword Is used to indicate which superclass you are extending when declaring a class Eg: class ColorPoint extends Point Implicit Subclassing If you don’t use extends, the class implicitly extends the class Object The super Keyword Allows a subclass instance method to invoke a superclass instance method o Eg: super.getx(); Allows a subclass constructor to invoke a superclass constructor o Eg: super(0.0, 0.0); Inheriting Structure A subclass inherits all the instance variables of all its superclasses, and may add its own An instance of the subclass has memory for its own instance variables, plus all the instance variables of its superclasses Inheriting Behavior A subclass inherits all the (non-private) methods of its superclasses o If not redefined, any method of any superclass can be invoked as if the subclass instance is acting like a superclass instance (polymorphism) o A subclass can redefine (override) a superclass method Can replace the method entirely Can augment the method by invoking the superclass method (using super), and
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/04/2010 for the course CPSC 233 taught by Professor Li during the Fall '09 term at University of Calgary.

Page1 / 4

Lecture 14 - Inheritance - The extends Keyword Is used to...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online