Appearance
Programming from First Principles - Practice Test 2
This test covers Modules 8-14.
Questions
- What is type inference?
- Why are user-defined classes useful?
- What is the difference between a class and an object?
- Define recursion and give its two essential parts.
- What is operational semantics?
- What is a protocol in Python-style design?
- Explain duck typing.
- What is polymorphism?
- Why should a recursive function have a reachable base case?
- Explain how two different classes can support the same protocol.
Answer Key
- The process of deducing a likely type from how a value or expression is used.
- They model domain concepts and combine related data with behavior.
- A class is a blueprint; an object is an instance created from that class.
- A function solving a problem by calling itself; it needs a base case and a recursive case.
- A description of how program expressions and statements execute or change state.
- A shared set of operations or behaviors that an object promises to support.
- Code uses an object's supported operations rather than requiring a specific class.
- One interface or operation working with values of different concrete types.
- Without it, calls may continue until a recursion error or resource exhaustion occurs.
- Each class implements the required methods, so the same client code can use either object.