oop linkedin assessment answers
1. Which statements best describe the Gang of Four design patterns called Memento and Observer?
- Memento notifies multiple classes of changes. Observer captures and restores an object’s internal state.
- Memento defers the exact steps of an algorithm to a subclass. Observer defines a new operation to a class without change.
- Memento alters an object’s behavior when its state changes. Observer encapsulates an algorithm inside a class.
- Memento captures and restores an object’s internal state. Observer notifies multiple classes of changes.
2. What is a reference to an obiect?
- It is the physical address of an object.
- It is the address where the variables and methods of an object are stored.
- It is a shallow pointer that contains the address of an object.
- It is the address of variables only-not the methods of an object.
3. Which choice is a benefit of using dependency injection?
- data abstraction
- code reusability
- loose coupling
- lazy initialization
4. Which statement is true?
- A default parameter’s constructor is not equivalent to the default constructor.
- A default constructor is inherited from a parent class.
- A default constructor cannot be defined by the coder.
- A default constructor can be called explicitly.
5. Which relationship best illustrates an abstract-concrete class relationship?
- color: red
- truck: window
- cat : kitten
- planet : moon
7. In addition to responsibilities, what should be listed on Class- responsibility-collaboration (CRC) cards?
- interacting classes
- attributes
- the programmer responsible for implementation
- which programming language will be used
8. How do object behaviors and attributes differ?
- Behaviors are vector quantities; attributes are scalars.
- Attributes describe a state; behaviors describe a change.
- Behaviors describe dynamic properties; attributes are static
- Attributes apply only to a specified object; behaviors apply to other linked objects.
9. What type of inheritance may lead to the diamond problem?
- multilevel
- hierarchical
- single level
- multiple
10. If a language just implements pass-by-value parameters to functions, can the objects passed as parameters be set to new instances inside the function and their new value will return to the caller?
- Yes, but only if it is a reference and not a primitive class.
- Yes, since the value is a reference even though it is passed by value, it can be done.
- No, a local copy will be initialized and will be lost as soon as it is out of scope.
- No, you will get a compilation error.
11. How many levels does multilevel inheritance allow in a program?
- as many levels of inheritance as required
- only 10 levels of inheritance
- only the amount of levels memory permits, divided by processor speed
- as many levels of inheritance as required within 10 minutes
12. What is a virtual method?
- a private method that you do not expect to be redefined in derived public classes
- a method that exists temporarily-once used, it ceases to be used by any caller
- a method that you expect may be redefined in derived classes
- a method that you do not expect to be redefined in derived classes
13. From the SOLID principles of object-oriented programming, which statement best describes the Liskov substitution principle?
- Software entities should be open for extension, but closed for modification.
- Many client-specific interfaces are better than one general-purpose interface.
- Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.
- A class should have only a single responsibility-that is, only changes to one part of the software’s specification should be able to affect the specification of the class.
14. What is the difference between a parameter and an argument?
- An argument is the variable used for input values in a method. A parameter is the specific input value passed to the method.
- An argument can have many values while a parameter can have only one value.
- Parameters and arguments are the same.
- A parameter is a variable in the declaration of a function. An argument is the value of this variable that gets passed to the function.
15. Why would you override a method of a base class?
- to define a class that can be inherited from
- to define a method that must be implemented in a derived class
- to define a custom implementation of an inherited member
- to define a method that must be implemented in a superclass only