CPSC 2150 Exam 1

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/102

flashcard set

Earn XP

Description and Tags

103 Terms

1
New cards
What should be included in a user story?
The role of the user, the action the user will take in the system, and the benefit to the user
2
New cards
Can the system itself be in a user story?
No
3
New cards
Which of the following are examples of non-functional requirements?

A. The system should run on Unix
B. The system must be written in Java
C. The user is able to view the status of their order
D. As a customer, I can place an order on the website, so I can place an order without having to call the store
A. The system should run on Unix
B. The system must be written in Java
4
New cards
What are the three parts of a UML class diagram?
The name, attributes, and methods of a class
5
New cards
(T/F) If you are creating a UML class diagram for a person, and that person will have multiple phone numbers, the data type of the "PhoneNumber" attribute should be a list or an array.
False
6
New cards
Which symbol is used to show that a method or attribute is private?
"-"
7
New cards
Which symbol is used to show that an attribute or method is package visible?
"~"
8
New cards
Which symbol is used to show that an attribute or method is public?
"+"
9
New cards
(T/F) In a UML Activity diagram, an "Activity" can be something that would take multiple lines of code to write, as long as it does not require and decisions
True
10
New cards
(T/F) In a UML Activity Diagram, an "Activity" cannot be a call to another function
False
11
New cards
(T/F) In a UML Activity Diagram, the text inside of an "Activity" or a "Decision" has to be written in code.
False
12
New cards
(T/F) In a UML Activity Diagram, a "Decision" may have multiple paths leaving it.
True
13
New cards
(T/F) Drawing UML diagrams is an important part of our design process.
True
14
New cards
Who is responsible for making sure the precondition of a method is true?
The implementer of the client code that calls the method
15
New cards
Who is responsible for making sure the postcondition of a method is true
The implementer of the method
16
New cards
At which times is it safe to assume that the invariants are true?
After the constructor of the class has completed, at the very beginning of a public method, and right after a public method has finished
17
New cards
(T/F) It is a best practice to have an if statement at the beginning of each method implementation to check that the preconditions are true
False
18
New cards
Every single class in Java extends the \___________________________ class
Object
19
New cards
If you do not override the toString method in a class that you create, what will happen when you call toString on an object of that class?
A string showing the memory address will be returned
20
New cards
What Java operator will tell us whether or not an object's data type is a certain class
instanceOf
21
New cards
Packages in Java allow us to have...

A. An array with different datatypes in it
B. A logical structure and grouping of classes
C. An opportunity to reuse the names of a class since it will be in a distinct package
D. Another layer of encapsulation by encapsulating classes together
B. A logical structure and grouping of classes
C. An opportunity to reuse the names of a class since it will be in a distinct package
D. Another layer of encapsulation by encapsulating classes together
22
New cards
(T/F) A class can be in multiple packages.
False
23
New cards
In Java, if you do not specify a visibility level for a class, the visibility level will be \________________________________
package
24
New cards
A static member belongs to the \______
class
25
New cards
(T/F) You can call a static member of a class without creating an instance of that class, by calling it directly from the class name.
True
26
New cards
If you have a reference type variable called foo that is declared final, which of the following cannot change?

A. The memory location that foo is pointing to
B. The abstract values stored inside of foo
A. The memory location that foo is pointing to
27
New cards
Which of the following can be the declared type in the Java programming language (as allowed by the compiler, not following any best practices we discussed).

A. Interfaces
B. Classes
A. Interfaces
B. Classes
28
New cards
Which of the following can be the dynamic type in the Java programming language (as allowed by the compiler)

A. Interfaces
B. Classes
B. Classes
29
New cards
Which of the following can be in an interface file?

A. private abstract methods
B. public abstract methods
C. public static final data variables
D. Private data variables
E. A constructor
F. Any type of public method
G. Any type of private method
B. public abstract methods
C. public static final data variables
30
New cards
(T/F) When determining whether or not you can call a method for an object in your code, the Java compiler will check to see if that method exists in the DYNAMIC type of the object
False
31
New cards
(T/F) Java requires that the DECLARED type of a variable must be the exact same as the DYNAMIC type of a variable
False
32
New cards
(T/F) A class can be the DYNAMIC type of a variable that has an interface as the DECLARED type if the class implements that interface.
True
33
New cards
What is "Coding to the Interface?" Note: the best practice, not the general idea of using interfaces.
Coding to the Interface is when you have all of your declared data types be interface data types, thus requiring your code to be written using only the methods provided by the interface and not specific to any implementation of the interface.
34
New cards
What is one benefit of following the best practice of "Coding to the Interface?"
You can change the implementation in your interface without affecting the client code.

Since your code is specifically written for the interface and not for any implementation, you can later change which implementation is used just by swapping out the constructor call that sets the dynamic type of the variable. Additionally any function that takes in a parameter will be taking in the interface type, and not the specific implementation type, which means any implementation can be passed in as the parameter for the method.
35
New cards
\_________________________ is ensuring that every object has its own role
Separation of concerns
36
New cards
\__________________________ is controlling access to data and operations
Information hiding
37
New cards
\__________________________ is grouping related data and operations together in one object
Encapsulation
38
New cards
(T/F) The precondition automatically checks and enforces itself by checking the value of the parameter and returning an error is the parameter is incorrect.
False
39
New cards
Who is responsible for making sure that the precondition for a function is met?
The client who calls the function
40
New cards
Who is responsible for making sure that the postcondition for a function is met
The implementer who codes the function
41
New cards
(T/F) It Is good practice to use an if statement to inside the method to check to see if the precondition is met
False (it's the client's job)
42
New cards
Which of the following is not a time when we would assume the invariant to be true?

A. After the constructor has finished
B. At the beginning of a public method
C. After a public method has finished
D. During the body of the public method or constructor
D. During the body of the public method of constructor (during execution)
43
New cards
Who is responsible for making sure a class invariant is true?
The implementers of the class and its public methods
44
New cards
It is a good idea to make data fields of a class public to make access to them easier and avoiding coding unnecessary getter and setter functions
False
45
New cards
Which is the best design practice?

A. Provide getter and setter functions to allow access to data members
B. Make data member public for direct access
C. Provide public member functions for controlling and observing abstract values of the objects, not just getting and setting.
C. Provide public member functions for controlling and observing abstract values of the objects, not just getting and setting.
46
New cards
What contains the actual code for a method?

A. The interface
B. The class that implements the interface
B. The class that implements the interface
47
New cards
What contains the private attributes?

A. The interface
B. The class that implements the interface
B. The class that implements the interface
48
New cards
In java, the declared type can be:

A. Only an interface
B. Only a class
C. Either an interface or a class
C. Either an interface or a class
49
New cards
In Java the dynamic type can be?
A. Only an interface
B. Only a class
C. Either an interface or a class
B. Only a class
50
New cards
(T/F) Our interface specification and the contracts in the interface can refer to private data variables.
False
51
New cards
A \________ can implement a \__________.
Class, interface
Abstract class, interface
52
New cards
(T/F) Java 8 and later allows private data fields in the interface.
False
53
New cards
Java 8 and later allows code in our interface as long as it is a \___________ method.
default
54
New cards
A \_____ operation needs access to the private data of a class.
Primary
55
New cards
A \_____ operation can be implemented by calling other existing operations.
Secondary
56
New cards
A \______ can extend a \___________.
Class, class
Interface, interface
57
New cards
When java is determining which version of an overridden method to run, how will it make that decision?
It will use the method in the dynamic type.
58
New cards
(T/F) An abstract class can only have data fields that are static.
False
59
New cards
(T/F) An abstract class can contain methods with bodies (code)
True
60
New cards
What is an example of a generic type you have already used?
List
61
New cards
(T/F) In order to pass a data TYPE in for the parameterized data type of a generic class, then the TYPE must be an immutable data type.
False
62
New cards
(T/F) In order to pass a data TYPE in for the parameterized data type of a generic class, then the TYPE must be an immutable data type.
True
63
New cards
Why do we hide information?
A. To keep data in sync
B. To keep data accurate
C. To keep data secure
D. To not overwhelm other programmers with implementation details
All of the above!
64
New cards
A good design helps with...
Reuse, debugging, and adapting to change
65
New cards
What are the two roles in a contract?
Implementer & client
66
New cards
A \_______________ (aka a requires clause) defines the client's responsibility., defines what the client must do before calling the code, can be related to the parameters, and can be the current state of the object
precondition
67
New cards
Why use preconditions?
Efficiency!

In the absence of preconditions, implementations will have to do error checking.
68
New cards
Consider an operation (or method) to perform a binary search to determine if an item is in an array.

What is the precondition?
The array must be sorted.
69
New cards
Consider an operation (or method) to perform a binary search to determine if an item is in an array.

What if the function checked the precondition on its own?
It would take linear time to check that the array is sorted, though it takes only log time to search, defeating the entire purpose of an efficient search!
70
New cards
Does an integer division operation have a precondition?
Yes! The divisor should not be 0.
71
New cards
A \______________ (aka an ensures clause) characterizes the implementer's responsibility (aka, your code).
postcondition
72
New cards
What do postconditions tell the client?
Tells the client what the code does (return values, events, state of the object)
73
New cards
Contracts are \____________, not actual code.
comments
74
New cards
Preconditions and Postconditions were about things that are true \________________ some method call or event
before AND after
75
New cards
The invariant may not be true when?
During the execution of a method
Before the call of a private method
After the call of a private method
76
New cards
(T/F) The implementer of any public class method is responsible for ensuring that the invariant is always true.
True
77
New cards
Who is responsible for the Invariant?
The implementer of the class defines the invariant
78
New cards
What are the two kinds of members in a class declaration?
Fields, ie data (determine the state)
and Methods, ie procedures (access/modify the state)
79
New cards
(T/F) Private members can be accessed only by instances of same class
True
80
New cards
(T/F) Private members provide concrete implementation / representation
True
81
New cards
(T/F) Public members can be accessed by any object
True
82
New cards
(T/F) Public members provide abstract view (client-side)
True
83
New cards
Who is the audience meant for preconditions and postconditions?
Preconditions and postconditions are meant for the client of the class (aka other software engineers)
84
New cards
Who are the invariants meant for?
the implementer
85
New cards
What is an interface?
Where interactions occur; describes what classes do, not how they should do it
86
New cards
The interface itself is \____ or \_____ visible.
public or package
87
New cards
What must the fields/attributes of an interface be declared as?
public static final (ie constants)

Cannot contain private fields/attributes
88
New cards
What must the methods of an interface be declared as?
public abstract

Cannot be final
89
New cards
(T/F) Class can declare more methods than required by interface
True
90
New cards
(T/F) Class can implement more than one interface
True
91
New cards
What is the difference between a declared type and a dynamic type (what time will they be declared)?
Declared type: set at compile time (by declaration), and a dynamic type: set at run time (by new)
92
New cards
(T/F) Compiler can infer dynamic type.
False
93
New cards
(T/F) Operator instanceOf tests the run-time type.
True
94
New cards
(T/F) Interfaces can be used as dynamic types.
False! Interfaces can only be used as declared types.
95
New cards
All dynamic types are \__________
classes
96
New cards
All runtime objects are constructed from a \_________, not a \________.
class, not an interface
97
New cards
\_____________________ allow us to tie the concepts specified in the interface to the private data in the implementation (ie our class)
Correspondences
98
New cards
Correspondences tie the \______________ to the \_______________.
Abstraction to the implementation
99
New cards
The implements relation may hold between a \___________ and a \___________.
Class and an interface
100
New cards
Java now allows code in our interface file as long as it is a \______or \_________ method
default or static