Inheritance should create a heirarchy where a subclass is a more specific or specialized version of its superclass. - In most cases (at least) an is-a relationship should hold, i.e. a subclass is-a superclass in that it has all attributes of the superclass, plus certain new attributes that provide greater specificity. - e.g. leap year is-a year chevrolet is-a car is-a land vehicle is-a vehicle Containment, when an object has a data members other object(s), is a has-a relationship, e.g. a complex number has-a real part and an imaginary part, each of which should be represented as a real number. The example of a shape such as a cylinder is semantically a has-a situation where a cylinder has-a point where it is centered, a radius, and a heighth. Virtual functions are in C++. Java doesn't have them. In C++, a function declared as virtual: - can only occur in a class ==> it is a member of an object ==> it is 'stored' within objects of the class's type * The storage of an object includes space for data members and addresses of member functions. With virtual functions, the address of each function will be stored in its object's activation record. For example, if you have an Employee heirarchy with subclasses salaried, hourly, and byPiece, then the base class can have a function getPay which is overwritten in each subclass. An object of type Salaried would contain the address of getPay() for that object-type, where an object of type Hourly would have the address of its version. Inheritance occurs via a pointer, where a pointer P to a base class can refer to any of its descendants as well. When P is pointed at a subclass, its activation record, which has space for getPay() in its Employee part, will fill that in with the address of the particular version of getPay() for the indicated subclass. In C++ a function must be declared virtual to 'switch on' polymorphism. - Without this, the address for any non-virtual functions will be the address of the type the pointer points at In Java, polymorphism is automatic. If a function is overwritten in a subclass, polymorphism is applied. - Declare an object of the superclass tpe, but new it so it refers to the subclass. A function that is: - overloaded has multiple versions, each with a different signature - overwritten has multiple version with the same signature, appearing in an inheritance heirarchy. In C++, this is the only possible outcome of overwriting. But in languages that permit nesting of subprograms, a local subprogram can shadow one at a higher scope level, i.e. the local function will be the one called when it is in scope. Example coming soon.