Database Abstraction and OOP Flashcards
What are some benefits of abstractions?
- Easier to think about
- Prevent access to things you shouldn’t see
- plug compatibility (replacement of pieces often without recompilation)
- Division of laber in software projects
What are the three key factors in OOP?
- Encapsulation (data hiding)
- Inheritance
- Dynamic method binding
Can you tell at compilation time what will be printed on the last line of the code below?

No. It depends if runtime uses static or dynamic binding.
Can x access field b?
x.b

No. Only the child (subclass) knows that the record goes farther the parent does.
What are dynamically bound methods called in C++?
Virtual
In C++, how are default methods bounded?
Statically
In Java, how are default methods bounded?
Dynamically (virtual)
(T/F) Non-virtual functions (static) require no space at run time. Explain.
True
The compiler just calls the appropriate version, based on the static type of the variable.
(T/F) Virtual functions are passed an extra, hidden, paramter.
True
Virtual functions in C++ have a dispatch table (vtable) for the class.
(T/F) Subclasses create their own vtables.

True

What happens if the order of the vtable methods get reordered?
All clients will have to recompile.
In Java, reordering the vtable and loosing linkage is resolved how?
Java uses symbolic links which are resolved after compile time to find the offset into the method table.
Give an example of repeated inheritance.
- Shared inheritance
- Replicated inheritance

What is a mix-in inheritance?
Single inheritance from on “real” base class, plus multiple inheritance from abstract classes (interfaces in Java).
Does a constructor allocate space?
No. It initializes the object.
(T/F) In C++, when an object of a derived class is created, the constructors for any base class will be executed before the constructor for the derived class.
True
(T/F) In C++ finalization, destructors for superclasses are called first followed by the destructor for the subclass.
False
Genericity VS Inheritance
Describe Genericity.
Parametric polymorphism:
- Type is explicitly parameterized
- Single copy of source code allows generation of versions that allow multiple types
Think of lists. (See horizontal relationship)

Genericity VS Inheritance
Describe Inheritance.
Subtype polymorphism:
- Can use an instance of a subclass wherever a class is expected.
See vertical relationship.
