Inheritance and method definition Flashcards
What are the 9 forms of inheritance?
What is specialization?
What is specification?
What is construction?
What is generalization?
What is extension?
What is limitation?
Behaviour of subclass is smaller or more restrictive than parent (excludes some operations)
- Often occurs when working with base classes that can’t be modified (similar to generalization in that sense)
- e.g. taking a list and making other data structures out of it via inheritance (e.g. a queue, a stack) – Need to turn OFF features we don’t want used
What is containment?
- Specialization (#1): is-a
- Containment: has-a
- Suppose UnprintableCharAtom has a CharAtom x as a data member.
- x can be private.
- We just don’t allow access to print() method
What is variance?
What is combination?
What does the stack frames look like for (instance of B is a subclass of A):
- Instance of A
- x = 55
- y = “Hello”
- Instance of B
- x = 77
- y = “Pizza”
- z = 1.135
Pointer-based objects (C++/Java) - someA is a pointer-to-A, someB is a pointer-to-B. Draw the the stack frame of what happens when we make someA point to a B instance.
In Stack-Based or Static Objects (C++ only), what happens if we try someA = SomeB?
For Stack-Based or Static objects(C++ only)
What happens if we try to make someB = someA?
In the following code, what does the following code snippets do?:
- private: int x;
- :Base(initX)
- What does Base::print()
- making int x private means it is Base’s job to manipulate it
- the :Base(initX) causes Base’s constructor to be invoked directly from Derived’s
- Base::print() invokes Base’s print method from within Derived’s
What does the following code output?
In the following code what do the following lines of code mean?:
- private int x;
- super(initX)
- super.print()
- private means it’s Parent’s job to manipulate that variable
- sends the variable to the super constructor
- uses the super classes’ print method
What is the output of the following code?:
In general, what are the 4 things subclasses can do?
What is the difference between replacement and inheritance?
Inheritance: If a subclass recieves a message for which it has no definition, the message is passed to the superclass.
Replacement (see below):