OOP Overview Flashcards

1
Q

Five basic concepts of Object Oriented Design:

A

classes and objects,
inheritance,
interfaces and methods,
encapsulation,
polymorphism.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A Maple (capital M) is a _______. We capitalize it because it’s the blueprint. When seeds drop and sprout, the growing maple tree is really an __________, or a type, of the Maple class. The growing maple tree is considered an _________, that is, an instance of a class.

A

class, instance, object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

________________ is a fancy word to describe the protection, or hiding, of data. The power of ____________________ is that you can protect certain data in certain classes from being used.

A

Encapsulation, objected-oriented design

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

An __________ of a Maple class (a maple) will change colors in the fall. To do so it needs a __________, or a function that performs an action.

A

instance, method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

An ___________ tells the object what it can do. For example, it tells a tree that it can grow.

A

interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

_____________ really means that the same thing can have different features.

A

polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

An object-oriented design consists of periodical and publication data. The hierarchy of classes, from top to bottom is as follows: Publication -> Book -> Novel. If the Novel class gains all methods and fields from the Book class, this is an example of which of the concepts of Object Oriented Design?

A

inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A parent class called SoftDrink has a brew() method. RootBeer and Beer classes inherit from SoftDrink. Each uses the brew() method but in different ways. Which aspect of object-oriented design is this?

A

polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

You are designing a program for payroll. The Tax class has a method to calculate tax rates based on pay. You want to keep this method and its variables invisible to other classes. They can access the method but don’t get to see its details. This is an example of _____.

A

Encapsulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

You are designing a program for vehicles. Some of the class names include Semi, Compact, and SUV. If we create a new semi, it is said that the semi is a(n) _____ of a(n) _____.

A

instance ; Semi class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

You have designed a hierarchy of classes for accounting software. All parent/child class relationships are set. What will you need for the classes to actually perform tasks?

A

Methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

An ________ is a component of a program that knows how to perform certain actions and how to interact with other elements of the program.

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

____________________ is an approach to problem solving where all computations are carried out using objects.

A

OOP

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A ______ is a blueprint of an object. You need to have a ________ before you can create an object. Objects have ________ and ___________.

A

class, class, methods, attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

A _________ is a procedure associated with a class and defines the behavior of the objects that are created from the class.

A

method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A ____________ is a combination of instructions that are combined to achieve some result.

A

function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

An object is ____________ when the class is invoked.

A

instantiated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

the _____________, creates the new instance.

A

constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

_____ means that classes can share the properties and methods from other classes

A

inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

create/instantiate a new instance of the Customer class?

A

Customer name = new Customer();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

The line of code that creates an object from the class is called a _____

A

constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Information can be _____ in a Java class, meaning available only to that class

A

Encapsulated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

An object is a(n) _____ of a class

A

instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

A Java _______ is a representation of an entity and an implementation of its behaviors.

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
________ is determined by a group of data values associated with the object (such as make, model, color, number of doors, horsepower, passenger capacity, etc.).
State
26
____________ is a series of methods that implement the object's functionality (such as start, accelerate, decelerate, turn, etc.).
Behavior
27
___________ is a unique ID used to identify the specific object from all other objects of the same kind (analogous to a real car's VIN number). This ID is used internally by the Java system to reference and track an object and is not directly changeable by the programmer or user.
Identity
28
A _________ is a description of a group of objects that have common properties and behavior
class
29
The _______ operator is used to create specific objects from a given class description.
new
30
A _____ must be specified before a specific instance of a Java object can be created.
class declaration
31
After constructing a specific object, the Java new operator returns _____.
a reference to the object
32
A _____ is a description of a group of objects that have common properties and behavior. It's a blueprint from which specific objects are created.
class
33
Actions are performed on an object by calling its _____.
methods
34
A specific instance of a class is created using the _____ operator.
new
35
the fancy term for creating a new instance of that class is _______________.
instantiation
36
_____________, inherit traits and properties from other objects
inheritance
37
The __________ tells the system to go out and grab some memory for the object and initialize variables.
constructor
38
________ constructors can be used by other methods in the same program or other programs. _______________ constructors are only used within the same program. ___________ constructors cannot be used outside of the current class.
Public, protected, private
39
What happens if you don't create a constructor for a class?
Java creates a default constructor Even though you won't see it in your source code, the default constructor is there, with empty brackets. E.g., if you had a class called Fonts, a constructor exists: Fonts () { }
40
Code for how new objects are created:
Employee emp = new Employee();
41
The same variable names can be used in the class and constructor. In the constructor, how do you differentiate them?
Use the this keyword If you have a variable for payRate in the class and as an argument to the constructor, refer to payRate in the constructor as this.payRate
42
If you call an overloaded method that doesn't exist, what will happen
The program will not compile
42
You can have overloaded methods of the same name and number of parameters, if only the _____ are different.
Data types
43
When you _____________ a method, you're actually creating another method with the same name. Each of the new methods has different ____________.
overload, parameters
44
When we alter a parent class's method inside a child class, that is called _______________.
overriding
45
When a class inherits from more than one class, this is known as ________________.
multiple inheritance
46
Java does not allow ____________________. In order to implement similar functionality, you can use Java interfaces. These are like classes but only have _______ and______________.
multiple inheritance, fields, methods
47
When using multiple interfaces to mimic multiple inheritance, what keyword is added before the method declaration?
override
48
From a technical perspective, why is multiple inheritance difficult in Java?
Java loads classes dynamically. You can't know which method(s) are valid.
49
The _____ problem describes the complexity of multiple inheritance in Java.
diamond
50
Which of the following code snippets illustrates a method of multiple inheritance in Java?
public class Z implements A, B { }
51
In order to inherit from the parent, use the keyword ____________ in the code.
extends
52
Polymorphism means _________
many forms
53
Polymorphism supports _____, which is several methods with the same name but different arguments.
overloading
54
The ____________ is a gateway to the actual code that runs the card game.
interface
55
Remember that interfaces let us avoid the restriction of multiple inheritance (also called _________________). An ______________ CAN inherit (extend) from multiple classes. When we create an interface, we can tell it to draw from multiple classes. We do this by using the _____________ keyword.
polymorphism, interface, extends
56
So how do we use an interface in a class? In Java, the keyword is ____________ to specify an interface to use.
implements
57
An ___________ class cannot be instantiated but is good for a class _______________.
abstract, hierarchy
58
Show the Oval class using the Shape interface?
public class Oval implements Shape {}
59
Remember that if a class uses an interface it _______________ it; if an interface draws on another interface, it _________________ it.
IMPLEMENTS, EXTENDS
60
An ______________ is an unscheduled, unplanned event that interferes with a program's processing.
exception
61
When Java encounters an exception, it __________ it
throws
62
The code that handles the error is called the _____________________
'exception handler'
63
We place the code we want to run in the _______ block, and any exception handling in the __________ block.
try, catch
64
Java keeps a list of exceptions and will know what exception has occurred. Where are these stored?
The Exception class, which is a subclass of the Throwable class, holds the classes for exceptions. That is, the exceptions for file not found, divide-by-zero, array index errors, etc., are subclasses of Exception.
65
You can think of a _______________________ as a recipe that describes the exact steps needed for the computer to solve a problem or reach a goal.
programming algorithm
66
In computer lingo, the word for a recipe is a ___________, and the ingredients are called _________. Your computer looks at your procedure, follows it to the letter, and you get to see the results, which are called ____________.
procedure, inputs, outputs
67
An algorithm always leads to a(n):
solution
68
An algorithm is written down as:
A list of steps
69
Instead of a list of steps, algorithms can be written using:
Flowcharts with arrows to illustrate the journey
70
An ____________________ is a technique that's used to measure the performance of the algorithms.
algorithm analysis
71
In order to improve things, the ___________________ can be used to measure the best, average, and worst-case time complexities of an algorithm.
asymptotic notations
72
Big Oh (O)
Measures the upper bound (worst case or maximum time)
73
Omega (Ω)
Measures lower bound (best-case or minimum time)
74
Theta (θ)
Measures both upper and lower bound.
75
An experimental analysis depends on the _____ results, so an algorithm cannot be measured unless an _____ is implemented.
output; equivalent program
76
In a linear function, the time taken is _____ if the size of the input is doubled.
In a linear function, the time taken is doubled if the size of the input is doubled.
76
Kara's code includes a binary search operation. Which of the following functions would be optimal to test the execution time of this function?
Logarithmic Function f(n) = log n, or O log (n) function is used for binary search algorithms where the input n is divided into 2 and and the search process continued till the element is found. The time to run the algorithm is equal to the log of the input size n.
77
Brian has an algorithm to read through an array that contains numbers 1 through 26 and convert each number to an English alphabet. He runs the algorithm a number of times with no changes to the size of the array and no changes to the task done. The function to use is: _____
The constant function f(n) = c or O(1) will help determine how much time it will take to complete a task when the size n is known and the task is the same. Here the size n is 26. The task is the same (converting numbers to alphabets) and does not change, irrespective of the number of times the task is performed.
78
An algorithm tests the air pressure on a slope at different altitudes. Given that the pressure depends on the altitude, what is the optimal algorithmic function to use?
This is a linear function because you are studying the relationship between pressure and height where the function is a straight line and there is a relationship between pressure and height, and the slope changes in a linear way in relation to the height or distance.
79
the measure of the maximum time taken by an algorithm to perform all its functions
time complexity
80
the amount of storage the algorithm needs in the memory to execute.
space complexity
81
For a linear function, what would be its time complexity?
The time complexity of a linear function is O(N)
82
If an algorithm runs in quadratic time, what is its time complexity using Big-O ?
The time complexity of a quadratic function is O(N2) .
83
Memory usage of an array
header- 8 bytes storing the size of the array- 4 bytes storage for the elements- number of elements * size of data type padding- extra bytes to make the final value a multiple of 8
83
If one for loop runs with size N and the other with size M and the loops follow a linear function, what is the expected time complexity?
O(M+N)
84
Which is the Java library that will help you access more tools to manipulate and sort arrays?
java.util.Arrays
85
What is Range sorting?
It's used when you only need some part of an array sorted.
86
What does the binarySearch method allow us to do?
Find the position of the item we're looking for in the array
87
How does Insertion-Sort work?
Finding if each item is in the right position of the array according to the criteria
88
If you use sorting methods contained in the Java library, do you have to code the sorting algorithm?
No, the library does all the sorting according to the set criteria
89
Bubble sort uses a _____ for-loop structure.
double
90
What is Bubble sort performance?
Bubble sort performance is O(n2)
91
Bubble sort compares _____ elements of an array at a time.
two
92
In the nested loop for the insertion sort, why do we decrement?
The sort orders from end to beginning
93
The methods in an interface have no ____________
bodies
94
What keyword is used when creating a class that uses an interface?
implements
95
What does it mean for a data type to be abstract?
The ways its behaviors are implemented are not defined.
96
Which Java language construct is commonly used to create abstract data types?
Interfaces
97
Which of the following Java statements best depicts the instantiation of the first element within a stack?
private Node top; We use a class (usually called Node) to represent an element in our linked list. Since the head of the list is the one we can use in a stack, we can name it top.
98
When creating a stack data type in Java, which methods are most appropriate for the interface to the Stack?
Push, pop, peek, size, isEmpty We must be able to add (push) and remove (pop) elements from the stack. We should also be able to view the top option (peek) without moving it, check the size, and determine if it is an empty stack.
98
What method is used to add data items to a stack in Java?
push() The push() method is that which adds elements to the collection of data items in the Stack.
99
When using a linked list to represent a stack, which element(s) do you have access to within the stack?
the top (tail) A stack is last-in-first-out, meaning you only have access to the top of the stack and therefore have to remove items from the top if you wanted to get to any other nodes.
100
The operations in Stack data structure is based on __________________, and it is predicated on the fact that there is only one entry point which also serves as exit point and called top.
last in first out
101
If you need to be able to add, move, and re-arrange train cars, you will need a better solution: ____________ is a data structure in which all elements are independent, but connected to each other.
a linked list
102
In a linked list, each element is called a _________ and contains a reference to the next node in the chain, and data (e.g., a string or number). The beginning is the ________; the end is the _________.
node, head, tail
103
When would it be most appropriate to create a linked list in Java?
storing elements in a dynamic array
104
When an item is removed from a linked list, what happens to the other element references?
Element indexes are re-ordered.
105
What is the function of the following code? tail = head; head = head.next;
The list is being rotated in a round-robin fashion.
106
What will the list look like if the following code is run: myList.addNodeToHead(75); myList.addNodeToTail(100); myList.addNodeToHead(50);
50, 75, 100
107
When you add a new element to the tail of a circularly linked list, what is true of the current tail?
It connects to the head
108
Why would an enhanced for loop not work with a circular linked list?
Nodes are all connected, it would result in infinite loop The list is like a railroad track in a circle, how do you know when to end? We use while and do...while loops to check to see if we are at the tail/head of the list.
109
If you need to remove an element from the tail of a circular linked list, what special step is needed?
Make sure the tail is really the last item
110
A ___________________ is a linked list where nodes are connected both forward and backward.
doubly linked list
111
The class uses _______ and ________ to maintain the previous and next connections.
next and prev
112
If you had a Java class called myDll, how would you create a new doubly linked list instance?
myDll dll = new myDll();
113
Which of the following correctly checks to see if the current node is the head of a doubly linked list?
Node myNode = new Node(element); if(myNode.prev == null) { } If the previous pointer is null, it means that the current node is the head of the list.
114
Java code snippet that correctly starts at the end of a Node called m?
if(m.next == null)
115
Queues are an ____________ data type that allow for efficient _____________ of lists.
abstract, manipulation
116
Which two methods add an element to the back of the queue?
add, offer
117
Which Queue Interface method retrieves the front element of a queue without removing it?
peek
118
Java statement with a queue name of 'myQueue' and the data of type integer?
myQueue.add(319);
119
Which construct is used by regular queues?
first-in, first-out
119
Which Queue Interface method retrieves and removes the front element of a queue?
poll The poll method retrieves the element from the front of the queue and also removes it.
120
Which method retrieves and removes the first element from a deque?
pollFirst
121
Which type of queue can be used as a queue or a stack?
Double-ended queue
122
Which method retrieves but does not remove the element at the head of the deque?
peek
123
In Java, a _____________ is used when we want to invoke methods on the queue based on a priority order.
Priority Queue
123
Which construct is used by stacks?
last-in, first-out
124
the __________ data type stores key-value pairs in an array
map array
125
________________ are a type of data structure used to efficiently store large sets of data. The data is stored in the form of _________________.
Hash tables, key-value pairs
126
When selecting a collision resolution method for Hash Tables, when are linked lists better than open addressing?
When the storage utilization is above 80% Open Addressing tends to run faster than linked lists up to 80% storage utilization, then the time grows exponentially
127
What is a collision in Hash Tables?
When the hash function assigns a key that has already been assigned
128
What are the main characteristics of a good Hash Function?
Easy to compute and uniform distribution A good Hash Function should be easy to compute to avoid high processing time and distribute uniformly to guarantee randomization
129
_____________________ are a searchable collection of elements characterized by a nodal tree structure.
Binary Search Trees (BST)
130
keys on the _________ of a node should be larger than the node and keys on the _________ side of a node should be less than that node
right, left
131