Method Parameters
Home ] Up ]

 

Secretary
ExecutiveSecretary
Manager
Executive
Programmer
Test Program

 

Subclass and Superclass Objects as Method Parameters

It is possible (and actually a very common practice) to declare a method with one or more parameters of superclass types, and then actually pass subclass objects.

For example, imagine that we had an expanded class hierarchy:

We need to add some new classes to represent this new hierarchy:
  • Secretary
  • Executive
  • ExecutiveSecretary
  • Programmer

and we also will make some modifications to the existing Manager class.

 

This page was last modified on 02 October, 2007