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
Q

________ is determined by a group of data values associated with the object (such as make, model, color, number of doors, horsepower, passenger capacity, etc.).

A

State

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

____________ is a series of methods that implement the object’s functionality (such as start, accelerate, decelerate, turn, etc.).

A

Behavior

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

___________ 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.

A

Identity

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

A _________ is a description of a group of objects that have common properties and behavior

A

class

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

The _______ operator is used to create specific objects from a given class description.

A

new

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

A _____ must be specified before a specific instance of a Java object can be created.

A

class declaration

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

After constructing a specific object, the Java new operator returns _____.

A

a reference to the object

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

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.

A

class

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

Actions are performed on an object by calling its _____.

A

methods

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

A specific instance of a class is created using the _____ operator.

A

new

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

the fancy term for creating a new instance of that class is _______________.

A

instantiation

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

_____________, inherit traits and properties from other objects

A

inheritance

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

The __________ tells the system to go out and grab some memory for the object and initialize variables.

A

constructor

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

________ 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.

A

Public, protected, private

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

What happens if you don’t create a constructor for a class?

A

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 () { }

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

Code for how new objects are created:

A

Employee emp = new Employee();

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

The same variable names can be used in the class and constructor. In the constructor, how do you differentiate them?

A

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

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

If you call an overloaded method that doesn’t exist, what will happen

A

The program will not compile

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

You can have overloaded methods of the same name and number of parameters, if only the _____ are different.

A

Data types

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

When you _____________ a method, you’re actually creating another method with the same name. Each of the new methods has different ____________.

A

overload, parameters

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

When we alter a parent class’s method inside a child class, that is called _______________.

A

overriding

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

When a class inherits from more than one class, this is known as ________________.

A

multiple inheritance

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

Java does not allow ____________________. In order to implement similar functionality, you can use Java interfaces. These are like classes but only have _______ and______________.

A

multiple inheritance, fields, methods

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

When using multiple interfaces to mimic multiple inheritance, what keyword is added before the method declaration?

A

override

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

From a technical perspective, why is multiple inheritance difficult in Java?

A

Java loads classes dynamically. You can’t know which method(s) are valid.

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

The _____ problem describes the complexity of multiple inheritance in Java.

A

diamond

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

Which of the following code snippets illustrates a method of multiple inheritance in Java?

A

public class Z implements A, B { }

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

In order to inherit from the parent, use the keyword ____________ in the code.

A

extends

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

Polymorphism means _________

A

many forms

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

Polymorphism supports _____, which is several methods with the same name but different arguments.

A

overloading

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

The ____________ is a gateway to the actual code that runs the card game.

A

interface

55
Q

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.

A

polymorphism, interface, extends

56
Q

So how do we use an interface in a class? In Java, the keyword is ____________ to specify an interface to use.

A

implements

57
Q

An ___________ class cannot be instantiated but is good for a class _______________.

A

abstract, hierarchy

58
Q

Show the Oval class using the Shape interface?

A

public class Oval implements Shape {}

59
Q

Remember that if a class uses an interface it _______________ it; if an interface draws on another interface, it _________________ it.

A

IMPLEMENTS, EXTENDS

60
Q

An ______________ is an unscheduled, unplanned event that interferes with a program’s processing.

A

exception

61
Q

When Java encounters an exception, it __________ it

A

throws

62
Q

The code that handles the error is called the _____________________

A

‘exception handler’

63
Q

We place the code we want to run in the _______ block, and any exception handling in the __________ block.

A

try, catch

64
Q

Java keeps a list of exceptions and will know what exception has occurred. Where are these stored?

A

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
Q

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.

A

programming algorithm

66
Q

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 ____________.

A

procedure, inputs, outputs

67
Q

An algorithm always leads to a(n):

A

solution

68
Q

An algorithm is written down as:

A

A list of steps

69
Q

Instead of a list of steps, algorithms can be written using:

A

Flowcharts with arrows to illustrate the journey

70
Q

An ____________________ is a technique that’s used to measure the performance of the algorithms.

A

algorithm analysis

71
Q

In order to improve things, the ___________________ can be used to measure the best, average, and worst-case time complexities of an algorithm.

A

asymptotic notations

72
Q

Big Oh (O)

A

Measures the upper bound (worst case or maximum time)

73
Q

Omega (Ω)

A

Measures lower bound (best-case or minimum time)

74
Q

Theta (θ)

A

Measures both upper and lower bound.

75
Q

An experimental analysis depends on the _____ results, so an algorithm cannot be measured unless an _____ is implemented.

A

output; equivalent program

76
Q

In a linear function, the time taken is _____ if the size of the input is doubled.

A

In a linear function, the time taken is doubled if the size of the input is doubled.

76
Q

Kara’s code includes a binary search operation. Which of the following functions would be optimal to test the execution time of this function?

A

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
Q

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: _____

A

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
Q

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?

A

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
Q

the measure of the maximum time taken by an algorithm to perform all its functions

A

time complexity

80
Q

the amount of storage the algorithm needs in the memory to execute.

A

space complexity

81
Q

For a linear function, what would be its time complexity?

A

The time complexity of a linear function is O(N)

82
Q

If an algorithm runs in quadratic time, what is its time complexity using Big-O ?

A

The time complexity of a quadratic function is O(N2) .

83
Q

Memory usage of an array

A

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
Q

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?

A

O(M+N)

84
Q

Which is the Java library that will help you access more tools to manipulate and sort arrays?

A

java.util.Arrays

85
Q

What is Range sorting?

A

It’s used when you only need some part of an array sorted.

86
Q

What does the binarySearch method allow us to do?

A

Find the position of the item we’re looking for in the array

87
Q

How does Insertion-Sort work?

A

Finding if each item is in the right position of the array according to the criteria

88
Q

If you use sorting methods contained in the Java library, do you have to code the sorting algorithm?

A

No, the library does all the sorting according to the set criteria

89
Q

Bubble sort uses a _____ for-loop structure.

A

double

90
Q

What is Bubble sort performance?

A

Bubble sort performance is O(n2)

91
Q

Bubble sort compares _____ elements of an array at a time.

A

two

92
Q

In the nested loop for the insertion sort, why do we decrement?

A

The sort orders from end to beginning

93
Q

The methods in an interface have no ____________

A

bodies

94
Q

What keyword is used when creating a class that uses an interface?

A

implements

95
Q

What does it mean for a data type to be abstract?

A

The ways its behaviors are implemented are not defined.

96
Q

Which Java language construct is commonly used to create abstract data types?

A

Interfaces

97
Q

Which of the following Java statements best depicts the instantiation of the first element within a stack?

A

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
Q

When creating a stack data type in Java, which methods are most appropriate for the interface to the Stack?

A

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
Q

What method is used to add data items to a stack in Java?

A

push()
The push() method is that which adds elements to the collection of data items in the Stack.

99
Q

When using a linked list to represent a stack, which element(s) do you have access to within the stack?

A

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
Q

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.

A

last in first out

101
Q

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

a linked list

102
Q

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 _________.

A

node, head, tail

103
Q

When would it be most appropriate to create a linked list in Java?

A

storing elements in a dynamic array

104
Q

When an item is removed from a linked list, what happens to the other element references?

A

Element indexes are re-ordered.

105
Q

What is the function of the following code?

tail = head;

head = head.next;

A

The list is being rotated in a round-robin fashion.

106
Q

What will the list look like if the following code is run:

myList.addNodeToHead(75);

myList.addNodeToTail(100);

myList.addNodeToHead(50);

A

50, 75, 100

107
Q

When you add a new element to the tail of a circularly linked list, what is true of the current tail?

A

It connects to the head

108
Q

Why would an enhanced for loop not work with a circular linked list?

A

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
Q

If you need to remove an element from the tail of a circular linked list, what special step is needed?

A

Make sure the tail is really the last item

110
Q

A ___________________ is a linked list where nodes are connected both forward and backward.

A

doubly linked list

111
Q

The class uses _______ and ________ to maintain the previous and next connections.

A

next and prev

112
Q

If you had a Java class called myDll, how would you create a new doubly linked list instance?

A

myDll dll = new myDll();

113
Q

Which of the following correctly checks to see if the current node is the head of a doubly linked list?

A

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
Q

Java code snippet that correctly starts at the end of a Node called m?

A

if(m.next == null)

115
Q

Queues are an ____________ data type that allow for efficient _____________ of lists.

A

abstract, manipulation

116
Q

Which two methods add an element to the back of the queue?

A

add, offer

117
Q

Which Queue Interface method retrieves the front element of a queue without removing it?

A

peek

118
Q

Java statement with a queue name of ‘myQueue’ and the data of type integer?

A

myQueue.add(319);

119
Q

Which construct is used by regular queues?

A

first-in, first-out

119
Q

Which Queue Interface method retrieves and removes the front element of a queue?

A

poll
The poll method retrieves the element from the front of the queue and also removes it.

120
Q

Which method retrieves and removes the first element from a deque?

A

pollFirst

121
Q

Which type of queue can be used as a queue or a stack?

A

Double-ended queue

122
Q

Which method retrieves but does not remove the element at the head of the deque?

A

peek

123
Q

In Java, a _____________ is used when we want to invoke methods on the queue based on a priority order.

A

Priority Queue

123
Q

Which construct is used by stacks?

A

last-in, first-out

124
Q

the __________ data type stores key-value pairs in an array

A

map array

125
Q

________________ are a type of data structure used to efficiently store large sets of data. The data is stored in the form of _________________.

A

Hash tables, key-value pairs

126
Q

When selecting a collision resolution method for Hash Tables, when are linked lists better than open addressing?

A

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
Q

What is a collision in Hash Tables?

A

When the hash function assigns a key that has already been assigned

128
Q

What are the main characteristics of a good Hash Function?

A

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
Q

_____________________ are a searchable collection of elements characterized by a nodal tree structure.

A

Binary Search Trees (BST)

130
Q

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

A

right, left

131
Q
A