Object Oriented Programming Quiz
Object Oriented Programming Quiz
Q2. For which case would the use of a static attribute be appropriate?
□ the number of people in each house in a small neighborhood
□ the lot size for each house in a small neighborhood
□ the color of each house in a small neighborhood
⊠ the weather conditions for each house in a small neighborhood
Q3. 1 Why would you create an abstract class, if it can have no real
instances?
⊠ to avoid redundant coding in children
□ to explore a hypothetical class
□ to prevent unwanted method implementation
□ to reserve memory for an unspecified class type
Q4. 2 Why would you create an abstract class, if it can have no real
instances?
⊠ to have common behavior in derived classes
□ to explore a hypothetical class
□ to prevent unwanted method implementation
□ to reserve memory for an unspecified class type
1
Q7. What is encapsulation?
□ defining classes by focusing on what is important for a purpose
⊠ hiding the data and implementation details within a class
□ making all methods private
□ using words to define classes
Q10. Which code creates a new object from the Employee class?
□ Employee currentEmployee = Employee.Create();
⊠ Employee currentEmployee = new Employee();
□ Employee currentEmployee;
□ Employee currentEmployee = Employee.New();
2
□ when an class is defined using the class keyword
□ every time an object is referenced
□ when an object is created from a class using the create keyword
Q15. Which two blocks are used to handle and check errors?
□ do and check
□ catching and trying
⊠ try and catch
□ do and while
3
Q19. Which statement is true?
□ A default parameter’s constructor is not equivalent to the default con-
structor
□ A default constructor is inherited from a parent class
⊠ A default constructor can be called explicitly
□ A default constructor cannot be defined by the coder
reference It is even mentioned in Wikipedia: “The constructors can be called
explicitly or implicitly. The method of calling the constructor implicitly is also
called the shorthand method.”
4
⊠ multiple
□ any type of inheritance
□ multilevel
□ hierarchical
- Single Inheritance is where a derived class inherits properties and behaviour from a singl
- Hierarchical Inheritance is where more than one derived class is created from a single bas
- Multiple Inheritance is for deriving a class from multiple base classes. Here, the child o
- Multilevel Inheritance is where a child class is derived from another derived class. This
- Hybrid Inheritance is a heterogeneous feature of using multiple inheritances. Here a child
reference
Q25. Two classes combine private data members and provide pub-
lic member functions to access and manipulate those data members.
Where is abstraction used?
□ Abstraction is using a private access specifier for the data members.
⊠ Abstraction is using public member functions to access and manipulate
the data members.
□ Abstraction is using the class concept with both data members and mem-
ber functions.
□ There is insufficient information to decide where abstraction is being used.
Q26. What are the five Creational Design patterns by the Gang of
Four ?
□ Observer, State, Strategy, Template Method, and Visitor.
□ Composite, Visitor, State, Prototype, and Singleton.
□ Composite, Builder, Factory Method, Prototype, and Singleton.
⊠ Abstract Factory, Builder, Factory Method, Prototype, and Singleton.
5
Q28. if an object is passed by reference, the changes made in the
function are reflected _.
⊠ to the main object of the caller function, too
□ on the caller function object and also the called function object
□ on the copy of the object that is made during the pass
□ only in the local scope of the called function
6
□ Duplication is easy to hide.
Q35. 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) {};
□ polymorphism, because each method can perform different task
□ method overriding, because it display the same method name, different or
same parameters, and same return type
⊠ method overloading, because it allows the creation of several methods with
the same name, wich differ by the type of input via parameter
□ method overriding, because it display the same method name, different
parameters, and same return type
7
□ the contents of a composition are all siblings
□ an aggregation contains only abstract classes
8
Q45. Which words in the following list are candidates for objects:
trumpet, clean, enrage, leaf, tree, collapse, active, and lively?
□ leaf and tree
□ clean, enrage, and collapse
□ clean, active, and lively
⊠ leaf, tree, and trumpet
9
Q51. What is a reference to an object?
□ It is the address of variable only – not the method of an object.
□ It is a shallow pointer that contains address of an object.
□ It is the physical address of an object.
⊠ It is the address where the variables and methods of an object are stored.
10
Q57. What is a copy constructor?
⊠ It is a unique constructor for creating a new object as a copy of an object
that already exists. There will always be only one copy constructor that
can be either defined by the user or the system.
□ It is a constructor that duplicates itself when requested on demand.
□ It is a common constructor for preventing the creation of a new object
as a copy of an object that already exists. There will always be multiple
standard constructors that can be either defined by the user or the system.
□ It is a constructor that duplicates itself on its own, based on memory
available.
Q59. There are five classes. Class E is derived from class D, D from
C, C from B, and B from A. Which class constructor(s) will be called
first if the object of E or D is created?
⊠ A
□ B
□ C
□ C and B
Q60. You have modules that are dependent on each other. If you
change one module, you have to make changes in the dependent
modules. What term is used to describe this problem, and what
is a potential solution?
□ Cohesion. A solution is to show that each module has certain responsibil-
ities and to use an anticohesive design pattern.
□ Encapsulation. A solution is to implement one of the SOLID principles to
ensure the modules do not encapsulate with each other.
⊠ Coupling. A solution is to refactor the code to be loosely coupled by using
inversion of control and dependency injection.
□ Dependency. A solution is to implement polymorphism and abstraction
to change and extract dependent elements of a module so that it functions
on its own.
11
□ A group of methods
⊠ A collection of objects
□ A list of children
Q67. Which statements best describe the Gang of Four design pat-
terns called Memento and Observer?
□ Memento notifies multiple classes of changes. Observer captures and re-
stores 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.
12
⊠ Memento captures and restores an object’s internal state. Observer noti-
fies multiple classes of changes.
Q68. What does the value (0.5,0.5,0.5) indicate in the class diagram
specification position: Coordinate = (0.5,0.5,0.5)?
□ a default value of the Coordinate attribute
□ the size of the position array
□ an increment of the position attribute value
⊠ a default value of the position attribute
13
reference link
14
Q75. What is the purpose of the finally block?
⊠ To always run the finally block of code when the try block exits
□ To run code when an exception has not occurred
□ To run the block if an exception occurred
□ To run code whenever garbage collection requires it
15
Q81. What does a concrete class not have?
□ parents
⊠ pure virtual functions
□ attributes
□ purposes
Q83. What is the difference between early binding and late binding?
□ Early binding is when a variable is assigned a value when a scope is created.
Late binding is when a variable is assigned a value after a scope is exited
□ Early binding is when a variable is assigned a value when the program
starts. Late binding is when a variable is assigned after the program is
running
□ There is no difference. In both cases, variables are assigned values when
a program has completed startup and is running
⊠ Early binding is when a variable is assigned its value at compile time. Late
binding is when a variable is assigned a value at run time
16
□ reference to base class // References to the base class are not required in
Java, Javascript & Python
□ reference to this pointer // While Python & Javascript may require passing
this or self in the constructor, It is not passed in Java constructor.
⊠ none // Above 3 are incorrect so “none” is the answer
Q89. What is the best name for the function that corrects this as-
sessment?
□ makeResult()
□ questionScore()
⊠ calculateScore()
□ getAnswers()
17
⊠ planet : moon
□ truck : window
18
□ You should increase coupling so that class members relate to the class
purpose.
□ You should limit coupling so that class members relate to the class objec-
tive.
Q100. Can you have two classes with the same name in the same
project?
□ No, you cannot.
□ Yes, as long as their constructors are different.
□ Yes, as long as their methods are different.
⊠ Yes, as long as they are in different namespaces.
19
⊠ reference
20
⊠ A collection of objects
□ A list of children
Q111. What are the five Creational Design patterns by the Gang of
Four ?
□ Observer, State, Strategy, Template Method, and Visitor.
□ Composite, Visitor, State, Prototype, and Singleton.
□ Composite, Builder, Factory Method, Prototype, and Singleton.
⊠ Abstract Factory, Builder, Factory Method, Prototype, and Singleton.
21
□ Interfaces can contain code or data. Abstract classes do not contain code
or data. A class can inherit from more than one abstract class but can
implement only one interface.
□ Interfaces can contain code or data. Abstract classes do not contain code
or data. A class can inherit from only one abstract class but can implement
an unlimited number of interfaces.
⊠ Abstract classes can contain code or data. Interfaces do not contain code
or data. A class can inherit from only one abstract class but can implement
an unlimited number of interfaces.
□ Abstract classes can contain code or data. Interfaces do not contain code
or data. A class can inherit from more than one abstract class but can
implement only one interface.
22
Q118. Are you required to return an object if it was passed by refer-
ence to a function, and why or why not?
□ Yes, the caller function needs to reflect the changes.
□ No, you should use a global variable instead.
⊠ No, changes will be automatically reflected in the calling function.
□ Yes, the object must be the same in the caller function.
Q121. What is the best name for the function that corrects this
assessment?
□ makeResult()
□ questionScore()
⊠ calculateScore()
□ getAnswers()
23