OOP Overview Flashcards
Five basic concepts of Object Oriented Design:
classes and objects,
inheritance,
interfaces and methods,
encapsulation,
polymorphism.
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.
class, instance, object
________________ 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.
Encapsulation, objected-oriented design
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.
instance, method
An ___________ tells the object what it can do. For example, it tells a tree that it can grow.
interface
_____________ really means that the same thing can have different features.
polymorphism
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?
inheritance
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?
polymorphism
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 _____.
Encapsulation
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) _____.
instance ; Semi class
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?
Methods
An ________ is a component of a program that knows how to perform certain actions and how to interact with other elements of the program.
object
____________________ is an approach to problem solving where all computations are carried out using objects.
OOP
A ______ is a blueprint of an object. You need to have a ________ before you can create an object. Objects have ________ and ___________.
class, class, methods, attributes
A _________ is a procedure associated with a class and defines the behavior of the objects that are created from the class.
method
A ____________ is a combination of instructions that are combined to achieve some result.
function
An object is ____________ when the class is invoked.
instantiated
the _____________, creates the new instance.
constructor
_____ means that classes can share the properties and methods from other classes
inheritance
create/instantiate a new instance of the Customer class?
Customer name = new Customer();
The line of code that creates an object from the class is called a _____
constructor
Information can be _____ in a Java class, meaning available only to that class
Encapsulated
An object is a(n) _____ of a class
instance
A Java _______ is a representation of an entity and an implementation of its behaviors.
object
________ 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
____________ is a series of methods that implement the object’s functionality (such as start, accelerate, decelerate, turn, etc.).
Behavior
___________ 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
A _________ is a description of a group of objects that have common properties and behavior
class
The _______ operator is used to create specific objects from a given class description.
new
A _____ must be specified before a specific instance of a Java object can be created.
class declaration
After constructing a specific object, the Java new operator returns _____.
a reference to the object
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
Actions are performed on an object by calling its _____.
methods
A specific instance of a class is created using the _____ operator.
new
the fancy term for creating a new instance of that class is _______________.
instantiation
_____________, inherit traits and properties from other objects
inheritance
The __________ tells the system to go out and grab some memory for the object and initialize variables.
constructor
________ 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
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 () { }
Code for how new objects are created:
Employee emp = new Employee();
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
If you call an overloaded method that doesn’t exist, what will happen
The program will not compile
You can have overloaded methods of the same name and number of parameters, if only the _____ are different.
Data types
When you _____________ a method, you’re actually creating another method with the same name. Each of the new methods has different ____________.
overload, parameters
When we alter a parent class’s method inside a child class, that is called _______________.
overriding
When a class inherits from more than one class, this is known as ________________.
multiple inheritance
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
When using multiple interfaces to mimic multiple inheritance, what keyword is added before the method declaration?
override
From a technical perspective, why is multiple inheritance difficult in Java?
Java loads classes dynamically. You can’t know which method(s) are valid.
The _____ problem describes the complexity of multiple inheritance in Java.
diamond
Which of the following code snippets illustrates a method of multiple inheritance in Java?
public class Z implements A, B { }
In order to inherit from the parent, use the keyword ____________ in the code.
extends
Polymorphism means _________
many forms
Polymorphism supports _____, which is several methods with the same name but different arguments.
overloading
The ____________ is a gateway to the actual code that runs the card game.
interface
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
So how do we use an interface in a class? In Java, the keyword is ____________ to specify an interface to use.
implements
An ___________ class cannot be instantiated but is good for a class _______________.
abstract, hierarchy
Show the Oval class using the Shape interface?
public class Oval implements Shape {}
Remember that if a class uses an interface it _______________ it; if an interface draws on another interface, it _________________ it.
IMPLEMENTS, EXTENDS
An ______________ is an unscheduled, unplanned event that interferes with a program’s processing.
exception
When Java encounters an exception, it __________ it
throws
The code that handles the error is called the _____________________
‘exception handler’
We place the code we want to run in the _______ block, and any exception handling in the __________ block.
try, catch
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.
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
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
An algorithm always leads to a(n):
solution
An algorithm is written down as:
A list of steps
Instead of a list of steps, algorithms can be written using:
Flowcharts with arrows to illustrate the journey
An ____________________ is a technique that’s used to measure the performance of the algorithms.
algorithm analysis
In order to improve things, the ___________________ can be used to measure the best, average, and worst-case time complexities of an algorithm.
asymptotic notations
Big Oh (O)
Measures the upper bound (worst case or maximum time)
Omega (Ω)
Measures lower bound (best-case or minimum time)
Theta (θ)
Measures both upper and lower bound.
An experimental analysis depends on the _____ results, so an algorithm cannot be measured unless an _____ is implemented.
output; equivalent program
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.
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.
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.
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.
the measure of the maximum time taken by an algorithm to perform all its functions
time complexity
the amount of storage the algorithm needs in the memory to execute.
space complexity
For a linear function, what would be its time complexity?
The time complexity of a linear function is O(N)
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) .
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
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)
Which is the Java library that will help you access more tools to manipulate and sort arrays?
java.util.Arrays
What is Range sorting?
It’s used when you only need some part of an array sorted.
What does the binarySearch method allow us to do?
Find the position of the item we’re looking for in the array
How does Insertion-Sort work?
Finding if each item is in the right position of the array according to the criteria
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
Bubble sort uses a _____ for-loop structure.
double
What is Bubble sort performance?
Bubble sort performance is O(n2)
Bubble sort compares _____ elements of an array at a time.
two
In the nested loop for the insertion sort, why do we decrement?
The sort orders from end to beginning
The methods in an interface have no ____________
bodies
What keyword is used when creating a class that uses an interface?
implements
What does it mean for a data type to be abstract?
The ways its behaviors are implemented are not defined.
Which Java language construct is commonly used to create abstract data types?
Interfaces
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.
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.
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.
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.
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
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
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
When would it be most appropriate to create a linked list in Java?
storing elements in a dynamic array
When an item is removed from a linked list, what happens to the other element references?
Element indexes are re-ordered.
What is the function of the following code?
tail = head;
head = head.next;
The list is being rotated in a round-robin fashion.
What will the list look like if the following code is run:
myList.addNodeToHead(75);
myList.addNodeToTail(100);
myList.addNodeToHead(50);
50, 75, 100
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
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.
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
A ___________________ is a linked list where nodes are connected both forward and backward.
doubly linked list
The class uses _______ and ________ to maintain the previous and next connections.
next and prev
If you had a Java class called myDll, how would you create a new doubly linked list instance?
myDll dll = new myDll();
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.
Java code snippet that correctly starts at the end of a Node called m?
if(m.next == null)
Queues are an ____________ data type that allow for efficient _____________ of lists.
abstract, manipulation
Which two methods add an element to the back of the queue?
add, offer
Which Queue Interface method retrieves the front element of a queue without removing it?
peek
Java statement with a queue name of ‘myQueue’ and the data of type integer?
myQueue.add(319);
Which construct is used by regular queues?
first-in, first-out
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.
Which method retrieves and removes the first element from a deque?
pollFirst
Which type of queue can be used as a queue or a stack?
Double-ended queue
Which method retrieves but does not remove the element at the head of the deque?
peek
In Java, a _____________ is used when we want to invoke methods on the queue based on a priority order.
Priority Queue
Which construct is used by stacks?
last-in, first-out
the __________ data type stores key-value pairs in an array
map array
________________ 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
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
What is a collision in Hash Tables?
When the hash function assigns a key that has already been assigned
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
_____________________ are a searchable collection of elements characterized by a nodal tree structure.
Binary Search Trees (BST)
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