05.0 Java Notes‎ > ‎

Inheritance and Polymorthism

Adapted with permission from Arnold Rosenbloom, University of Toronto 
*added by MisterV

Inheritance (IS-A): method for extending existing classes by adding methods and fields

Subclass and superclass
  • what it means:  a subclass inherits all methods and attributes of superclass. (ie Shapes )
Object: is the superclass of all classes.

extends: 
  • used to define subclass/superclass relation between two classes.
Method overriding:
  • Method in subclass has same name as method in superclass. In Java, method search proceedes from class of instance back towards Object.

Method overloading*: 
  • A method is overloaded when other methods of the same name exist either in the class or in any subclass and the parameter list differs from the orginal method.

Overloading vs Overriding*:
  • To override an inherited method, the method must be declared exactly as the method in the superclass. That includes both the number and type of parameters. If the name is the same but either the number or type of parameters differ, then the new method overloads the method the inherited method from the superclass.

Polymorphism: 
  • behaviour varies depending on the actual type of an object.
Comments