Comp-345 OOP Quizes
A method is polymorphic if the action performed by the method depends on the actual type of the object to which the method is applied.
True
C++ compilers disallow any member function calls for const objects unless the member functions themselves are also declared const.
True
It is possible to have nontype parameters; a nontype parameter can have a default argument and the nontype parameter is treated as const.
True
Private data members can be accessed from both private and public member functions.
True
The name of a type parameter can be used only once in the formal type parameter list of the template definistion
True
_____________ is a Java compiler's ability to look at each method invocation and corresponding declaration to determine the type argument (or arguments) that make the invocation applicable.
Type inference
Represent an operation to be performed on the elements of an object structure. Lets you define a new operation without changing the classes of the elements on which it operates.
Visitor
Should comparison operator functions be const?
Yes
Can a local variable in a function be defined with the same name as a global variable? If so, how does the programmer syntactically differentiate between the two?
Yes, by accessing the global variable using ::
In this example what does myMap refer to? Map<String, List<String>> myMap = new HashMap<>();
a HashMap of String
Suppose that Kumquat is the name of a class and that fruit is a variable of type Kumquat. What is the meaning of the statement "fruit = new Kumquat();"? That is, what does the computer do when it executes this statement? (Select the options that are true)
a new object is made of type Kumquat and stored on the heap fruit is a reference to the new Kumquat the default constructor of the type Kumquat is executed
A pointer-based string is a built-in array of characters ending with.
a null character '\0'
Which of the following are true concerning the terms subclass and superclass?
a subclass inherites member variables and methods from its superclass a subclass is also know by the term derived class several classes can be declared as subclasses of the same superclass
The keyword public is a(n) ____________________.
access specifier
A class' "get" method used to return a copy of a private datamember is sometimes called an _______________ function.
accessor
Stack, queue and priority_queue are container ____________ . They are not first-class containers, because they do not provide the actual data-structure implementation in which elements can be stored and because they do not support iterators.
adapters
STL __________________ are functions that perform such common data manipulation operations such as searching, sorting, and comparing elements (or entire containers).
algorithms
In the context of Fowler's article, we would prefer that our application have a dependency on:
an interface
The STL's ________________ containers provide direct access to store and retrieve elements via keys
associative
The member-initializer lists is executed ________________ the constructor body.
before
Declare a pointer to a Boolean function that takes two integers as arguments. The pointer's name should be functionPointer. Include a ; at the end. Include NO whitespace.
bool (*functionPointer) (int, int);
To declare a ______________ type parameter, list the type parameter's name, followed by the extends keyword, followed by its upper bound.
bounded
Generics add stability to your code by making more of your bugs detectable at ____________ time.
compile
Who or what generates classes from template classes?
compiler
Fowler uses the term ________________________ to mean "a glob of software that's intended to be used, without change, by an application that is out of the control of the writers".
component
What best describes the variable p in this context? int* const p = new int;
constant pointer to non-constant data
A _______________ is a function with the same name as the class and is used to initialize the object it is working on.
constructor
A ______________ constructor is a single argument constructor that turns objects of other types (including built-in types) into objects of a particular class.
conversion
A ______________ constructor is a constructor that can be called with no arguments.
default
A constructor that defaults all of its arguments or explicitly requires no arguments is a _______________ constructor.
default
The STL class template __________________ provides efficient insertions and deletions at the the front a back of the list and efficient access to any element.
deque
A function with the same name as the class but receded with a tilde character (~) is called the __________________ of that class.
destructor
A constructor that is declared _______________ cannot be used in an implicit conversion.
explicit
Fowler considers "Inversion of Control" to be a _______________ term.
generic
In same cases it is desirable to input an entire line of text into a built-in array of chars. For this purpose, the cin object provides the member function
getline
The qualifier ________________ before a function's return type in the function definition "advises" the compiler to generate a copy of the function's code in place when appropriate to avoid a function call.
inline
One of the fundamental principles of good software engineering is to separate _____________ from implementation. This makes it easier to modify programs.
interface
_____________________ are objects used to access elements within the STL containers. These objects are often used as if they are pointers to walk through the elements of a container but they hold extra state information sensitive to the particular container.
iterators
Frameworks that provide a general capability to assemble components from different layers (such as a controller architecture and a database back-end):
lightweight containers
The STL class template ______________ is implemented as a linked list and provides an efficient implementation for insertions and deletions anywhere.
list
___________ is the STL associative container that is most similar to a "dictionary". It provides a 1 to 1 mapping between a key and a value.
map
const data members and reference data members must have their values set in the ___________________ portion of the constructor
member initialization list
Classes can extend friendship to other classes and __________________.
methods
The _______________ operator automatically creates an object of the proper size, calls the constructor for the object and returns a pointer of the correct type.
new
Will this syntax compile? Box<Double> box = new Box<Double>(); Box<Number> box2 = box;
no
When two functions of the same name have differing types in their parameter lists; the function are called _________________.
overloaded
Class templates are also called _____________________ types.
parameterized
If we wish to deploy this system in different ways, we need to use __________ to handle the interaction with these services so we can use different implementations in different deployments.
plugins
The "dummy" or "garbage" parameter is used with the __________________ increment operator?
post
A ______________ type is the name of a generic class or interface without any type arguments.
raw
A function that calls itself:
recursive
Default arguments must be the _________________ arguments in a function's parameter list.
right-most (trailing)
Using quotes rather than angle brackets to include a header files tells the compiler to look in the __________________ for the file.
same path as the current source file
The Dependency Injection and Service Locator patterns share the principle of:
separating configuration from use
STL ______________ containers include vector, list and deque
sequence
According to Fowler, a _______________ is like a component but it will be used remotely through some interface, either synchronous or asynchronous (eg web service, messaging system, RPC, or socket.)
service
Design patterns are _________________+ that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time.
solutions to general problems
Each object of a class has its own copy of all the data members of the class. In certain cases all objects of a class should share only one copy of a variable. A____________________ class variable is used for these and other reasons.
static
______________ member functions are the only member functions that do not receive this as an implicit first argument.
static
Template syntax
template <typename T>
Every object has access to its own address through a pointer named ______________.
this
When we are working inside a class and you use a simple name to refer to an instance variable like test1, where is the object that contains the variable?
this
Generics enable _____________ to be parameters when defining classes, interfaces and methods.
types
By convention, type parameter names are single, _______________ letters.
uppercase
A(n) _____________ function is NOT part of a class' interface; rather, it is a private member function that supports the operations of the class' public member function.
utility
The STL class template ________________ is a data structure that provides contiguous memory locations that allows for efficient direct access to element in the list using subscripts [].
vector
Assume the operator + has been overloaded for the user defined data type Date. Given three Date objects x, y and z, the address of which object will be the "this" pointer passed to operator+? x = y + z;
y
Will the following syntax compile: Box<Number> box = new Box<Number>(); box.add(new Integer(10)); box.add(new Double(10.1));
yes
Why is the syntax this.data_member or this.member_function() illegal syntax?
"this" is a pointer, so the -> operator must be used instead of a .
Provide first compiler directive (aka. preprocessor directive) used to prevent the redefinition of a class when the header file is included more than once. Hint: There are three compiler directive statements used to accomplish this. Only provide the first one. The class name is Example so used (EXAMPLE_H).
#ifndef EXAMPLE_H
What is the unary operator that obtains the memory address of its operand?
&
Which 3 of the following operators can be used with user defined type without overloading them?
& , =
Given a pointer to an object p declared: pExampleClass* p = new ExampleClass(); There are two ways of derefencing the pointer and calling a method named fun. One way is: p->fun(); the second is
(*p).fun();
Which 2 of the following operators cannot be overloaded?
. ::
Given the double pointer, p, is pointing to address 1000; where is it pointing after the following operation? p++;
1008
Object-oriented programming uses classes and objects. What is the relationship between classes and objects?
A class is a kind of factor, or blueprint, for constructing objects
These design patterns are specifically concerned with communication between objects.
Behavioral Patterns
Pattern builds a complex object using simple objects and using a step by step approach
Builder
PicoContainer is a type of ____________ Injection
Constructor
These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using the new opreator. This gives program more flexibility in deciding which objects need to be created for a given use case.
Creational Patterns
_______________________is to have a separate object, an assembler, that populates a field in the lister class with an appropriate implementation for the finder interface,
Dependency Injection
Friendship can be extended to a template
False
It is possible to create new operators (by "new operators," I mean operators that are not built into C++).
False
Keywords class and typename as used with a template type parameter specifically mean "any user-defined class type."
False
Operator overloading can change the meaning of how an operator works on objects of built-in types.
False
Overloading can change the precedence of an operator.
False
To make an abstract class in Java the programmer should label one or more of it's methods as pure virtual.
False
Java uses "garbage collection" for memory management. Which of the following are true about garbage collection in Java?
Garbage collection is used to reclaim memory occupied by objects that are no longer accessible to a program Garbage collection is an old idea but is now possible in languages such as java because of the speed of modern computers.
What are instance variables and instance methods?
Instance variables are contained by an object and instance methods operate on these variables
Avalon is an example of a framework that uses ________________ injection.
Interface
This pattern is used to get a way to access the elements of a collection object in sequential manner without any need to know its underlying representation.
Iterator
If several classes are generated from a single class template with a single static data member, do all of the specializations share a single copy of the static data member?
No
Which of the following are true for the key word null in Java?
Null is a value stored in a variable, not a pointer to something else It is illegal to involke a method using a null reference
Spring is an example of _________________ injection.
Setter
This pattern involves a single class which is responsible to create an object while making sure that only single object gets created. This class provides a way to access its only object which can be accessed directly without need to instantiate the object of the class.
Singleton
Select all of the following that are listed in the reading as benefits of using generics.
Stronger type checks at compile time Elimination of casts Enabling programmers to implement generic algorithms
These design patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities.
Structural Patterns
The authors of the Design Patterns book are collectively known as:
The Gang of Four