CMPSC 32 Lecture Notes - Lecture 11: Return Type, Subtyping, Postcondition
Document Summary
You can have inheritance without polymorphism and vice versa. Preconditions cannot be strengthened in a derived class. Postconditions cannot be weakened in a derived class. If you"re not careful, you can violate the above constraints. Signature of a method is the type of its parameters and return values. Only when the semantics support the subtype/lsp relationship. Add methods to existing class rather than subclass it. Specify what external code (including derived classes) knows about the inheritance relation. Protected: only the class, derived classes, and friends can access. Private: only the class and friends can access. Only d is aware that it is-a c. Public members of c are private in d. External code does not consider an instance of d to be-a c. A d instance not substitutable for a c. Example class a { public: int x; protected: int y; private: int z; class b : public a {