OPO Flashcards
What is an example of dynamic binding?
Method overriding
For which case would the use of a static attribute be appropriate?
The weather conditions for each house in a small neighborhood
Why would you create an abstract class, if it can have no real instances?
to avoid redundant coding in children. and to have common behavior in derived classes
When does static binding happen?
at compile time
What is the best reason to use a design pattern?
It will result in code that is more extensible and maintainable
What is encapsulation?
hiding the data and implementation details within a class
What is an is-a relationship?
A subclass object has an is-a relationship with its superclass or interface
You want a method with behavior similar to a virtual method. It’s meant to be overridden, except that it does not have a method body. It just has a method signature. What kind of method should you use?
an abstract method
Which code creates a new object from the Employee class?
Employee current Employee = new Employee();
Which type of constructor cannot have a return type?
Trick question, constructors do not have a return type
When is a constructor executed?
When an object is created from a class using the new keyword
If a local class is defined in a function, what is true for an object of that class?
The object can be accessed, declared, and used locally in that function.
Which two blocks are used to handle and check errors
try and catch
Why would you implement composition using an id instead of a reference?
It makes it easier to save the entity
It can make the entity retrieval more efficient
It minimizes coupling
Which statement best describes the method of inheritance in OOP?
Inheritance describes the ability to create new classes based on an existing class
Which type of inheritance, when done continuously, is similar to a tree structure?
Hierarchical
Is a default parameter’s constructor equivalent to the default constructor?
No
What are some advantages of using getters and setters?
Getters and setters provide encapsulation of behavior
Getters and setters provide a debugging point for when a property changes at runtime
Getters and setters permit different access levels.
In context of OOP, what is association?
Association is a relationship where all objects have their own life cycle and there is no owner
How are user stories different from use cases?
User Stories are shorter and less detailed
Which type of inheritance must be used so that the resultant is hybrid?
Multiple and hierarchical
Hybrid inheritance is a composition of multiple and hierarchical inheritances
A language that does not support polymorphism but supports classes is considered what?
an object-based language
If two classes combine some private data members and provides public member functions to access and manipulate those data members. Where is abstraction used?
Abstraction is using public member functions to access and manipulate the data members
What are the five Creational Design patterns by the Gang of Four?
Abstract Factory Builder Factory Method Prototype Singleton
In multilevel inheritance, one class inherits how many classes?
one class only
if an object is passed by reference, the changes made in the function are reflected ____.
to the main object of the caller function, too
A mobile phone is made up of components such as a motherboard, camera, and sensors. The motherboard represents all the functions of a phone, the display shows the display only, and the phone is represented as a whole. Which of the following has the highest level of abstraction?
The mobile phone
Which class has the highest degree of abstraction in a multilevel inheritance relationship of five levels?
the class at the first level
Which is NOT one of the basic types of inheritance?
double inheritance
Why is code duplication so insidious?
One has to maintain all the duplicates
When and how often is a static constructor called?
It is called initially when an object is created and only one time
What does the code shown below demonstrate, and why?
static void Multiply(int num1, int num2) {};
static void Multiply(double num1, double num2, double num3) {};
static void Multiply(float num1, float num2) {};
Method overloading
It allows the creation of several methods with the same name, which differ by the type of input via parameter
What is the purpose of a static constructor?
To initialize all the members with static value
What are CRC Cards?
Class responsible collaboration cards are a brainstorming tool used in the design of oop software
How are contents of a composition different from those of aggregation?
if a composition dies, the contents die