CMPSC 32 Lecture Notes - Lecture 11: Return Type, Subtyping, Postcondition

58 views4 pages
26 Sep 2017
School
Course
Professor

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 {

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents