Final Exam

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/100

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

101 Terms

1
New cards
What is top down development?
A problem solving approach where you break a task down into smaller subtasks
2
New cards
Procedural abstraction
Using methods to define tasks and hide complexity.
3
New cards
2 parts of a method?
Declaration and body
4
New cards
What are the 4 parts of the method declaration?
Access level, return type, name, and parameters
5
New cards
What is the difference between access level and access modifier?
Access level is what determines the accessibility of a method, whereas an access modifier is the specific keyword used to determine that
6
New cards
What is another word for access level?
**Visibility**
7
New cards
What is a class method?
A method declared with the access level “static”, which means it can only be called from the class itself and cannot be called by objects of that class.
8
New cards
What are parameters?
Something that can accept values to pass into the method. When a method is called, parameters allow that statement to pass information into that method for it to manipulate.
9
New cards
Can methods change the data stored in an argument?
No, they cannot change what was passed into them. Parameters pass a **copy** of the value to the method for it to manipulate and return something new, but methods **cannot** change the actual value of the parameter.
10
New cards
What happens when you pass an object into a method?
It gives that method a copy of the reference to the object.
11
New cards
How do you separate multiple parameters?
With commas
12
New cards
What is method overloading?
When multiple methods have the same name. The computer differentiates between them by the number and type of their parameters.
13
New cards
What does the return statement do?
Return a value from the method back to the calling statement
14
New cards
What does the keyword void do?
It means that the method doesn’t have to return anything
15
New cards
What are the three parts in a method documentation?
The function, precondition and the post condition
16
New cards
What is the function in method documentation?
It gives a basic overview of what the method does
17
New cards
What is the precondition?
The basic requirements for a method to run. Does not exist for all methods
18
New cards
What is the postcondition?
Describes what is true after the method has been executed
19
New cards
What is a call?
A statement that contains a method name followed by parenthesis. Make the code jump to that method and execute whatever code is inside.
20
New cards
What does local mean?
It means that something is restricted to the piece of code where it was defined. In the context of methods, it means that any variable, object or constant defined in a method can **only** be access by that method and nothing else
21
New cards
What are the two key parts of an object?
Its **state** and its **behavior**
22
New cards
What is the state of an object?
The **data** it stores
23
New cards
What is the behavior of an object?
The **actions** and **communications** it provides
24
New cards
What is the relationship between an object and a class?
A class defines the **variables** for the state of an object and the **methods** for the behavior of that object, and an object is a **reference of a class**.

\
\
It’s like classes are the **blueprints** for objects
25
New cards
What is encapsulation/information hiding?
When you protect an objects data by only allowing it to be changed by methods defined by the object
26
New cards
What is a class?
A data type that defines variables and methods for the state and behavior of objects.
27
New cards
What is client code?
An application that uses one or more classes
28
New cards
What is contained in a class declaration?
**access level** + class + **name** + {}

\
ex: public class Circle {}
29
New cards
What goes inside the body of a class?
Variables, constructors and methods
30
New cards
What are members of a class?
The **variables** and **methods** in that class
31
New cards
What is a constructor?
A method used when objects of a class are created- called **instantiation**. Every time a new object is created the constructor method is called to make it.

\
The constructor can be helpful to assigning data to an object at the start.
32
New cards
What is the syntax of a constructor?
Constructors are always public, and have the same name as the class.

\
public + (name of the class) (parameters) {}

\
\
Ex:

\
public Circle (double radius, int diameter) {}

\
or:

\
public Box () {}
33
New cards
Can a class have multiple constructors?
Yes, and the compiler will determine which one to use based on the number and types of the parameters
34
New cards
Are classes always public?
Yes! You can declare it as private, but then nothing else could use it and it would defeat the purpose
35
New cards
Can members of a class be private?
Yes, the variables and methods inside of a class can be private.
36
New cards
What are the three kinds of methods a class can have?
**Accessor:** Used to determine the value of a variable. Usually named something like **get**Radius. The **get** shows that the method is used to **access** or retrieve values

\
**Modifier:** Changes the values of variables in the class.

\
**Helper:** Methods with the access level **static** that are **only** used within the class by other methods to complete tasks
37
New cards
What are instance variables?
Each object has a **copy** of the variables in the class. These copies are called **instance variables**. Since an object is an instance of a class, it’s variables are **instances** of the class variables.
38
New cards
What are class variables?
Variables declared with **static**, meaning objects cannot change them or get a copy of it. There is only **one** that all the objects can refer to.
39
New cards
What are instance methods?
Methods that change the state of an object. This includes **accessor** and **modifier** methods
40
New cards
What are class methods?
Methods called from the class itself rather than through an object of that class
41
New cards
What is the object class?
Though objects are all **instances** of another class, the **Object** class is the **superclass** of all classes.
42
New cards
What methods do classes inherit from the Object superclass?
**equals**(obj) - This returns true if the object in the parameters is equal to the object the method was called by

\
**toString**() - Returns a String to represent the object
43
New cards
What is ClassCastException?
An error thrown when you use the equals method on two noncompatible objects, like a string and int object
44
New cards
Can classes override the equals and toString methods of the object superclass?
Yes, they can override it to better fit their function and purpose
45
New cards
What is a **has-a** relationship?
When classes have another class. For example, Strings are a class of object. A class with a **string member** is demonstrating a has-a relationship
46
New cards
What is the **this** keyword?
When using the same name for your **parameters** and the member variables of a **class,** you can diffrentiate between the two with **this**

\
Ex:

private double **balance**;

\
public Account(double balance) {

this.balance = balance;

}

\
The constructor took in a parameter called balance, but wanted to assign it to the class’s member variable called balance
47
New cards
What is object-oriented-development?
An approach to creating software that uses a system of objects that communicate with each other to provide solutions to tasks
48
New cards
\
What is polymorphism?
An OOP program features that allows objects to assume different types.
49
New cards
\
When you assign an object a different class, what happens?
It now uses the methods and members of the new class it was assigned.

\
Example:

\
```javascript
Circle wafer;
Disk cookie = new Disk(2, 0.5);
wafer = cookie; //Wafer began as a circle, now a Disk
```
50
New cards
What is reusability in OOP programming?
It means you can reuse the data and members of a class endlessly by creating objects from them. It **reduces** development time and **decreases** the likelihood of bugs
51
New cards
What is modular programming?
A way of programming where each class are in separate files and can be pieced together or used through objects.
52
New cards
What is **inheritance?**
Creating another class that **extends** an existing class. Usually this is done when programmers want to create a class that is similar to an existing one, but more specific.

\
For example, creating a very specific Honda class that **extends** the Car class
53
New cards
How do you extend a class?
Include the keyword **extends** in the class declaration:

\
public class (class name) extends (other class name) {}
54
New cards
\
In inheritance, what can the “top” class that other classes inherit from be called?
The super class, base class, or parent class
55
New cards
\
In inheritance, what can the “bottom” class that inherits from the parent/base/super class be called?
The derived class, subclass, or child class
56
New cards
\
What happens when you inherit a class?
You get all of the classes methods and members that were declared public
57
New cards
\
Can you inherit all methods or members of a base class?
No, you cannot access methods or members of a class that are declared private or static
58
New cards
\
What is an **is-a relationship**?
An is-a relationship is the relationship demonstrated when a class is derived from an existing class.

\
\*This is different from a has-a relationship, which is when a class uses objects from another class.
59
New cards
\
Can a class inherit multiple classes?
No, java only allows a class to inherit one other class.
60
New cards
\
How do you call methods of the base class from the subclass?
The super keyword allows you to call methods from the base class in the subclass, access methods from the subclass, and use its constructor.

\
In simple terms; the super keyword allows you to access all public characteristics of the base class
61
New cards
\
When an object of a subclass is created, what happens?
The constructor for that subclass is called. However, the constructors for the class it inherits from is also called.

\
Objects that are part of a hierarchy will call the constructors of the classes they are instances of or extend

\
\*Note that this only happens if none of the constructors have parameters. If they do, the super keyword must be used.
62
New cards
\
Can a subclass override inherited methods?
Of course! One of the main purposes of inheritance is not only for code reusability, but to also give subclasses a framework that they can tailor to the objects specific needs.
63
New cards
\
What is an **abstract class**?
A class that defines an abstract concept.

\
For example, a Plant class. There is no such thing as a *plant*. There are trees, and dandelions, but no *plant*.
64
New cards
\
Can abstract class be instantiated? (Can an object be created from them)
No, abstract classes cannot be instantiated because they are supposed to represent abstract concepts.
65
New cards
\
What keyword do you use to create an abstract class?
Abstract
66
New cards
\
What are abstract methods?
These are methods that must be implemented in the subclasses of an abstract class, but are not defined in the abstract class.
67
New cards
\
How do you write abstract methods in an abstract class?
To create an abstract method you include the keyword abstract, and define the method’s return type and parameters, but no method body.

\
```java
abstract String makeSound();
```
68
New cards
\
Do abstract methods have to be implemented in the subclasses that inherit from the abstract class?
Yes, they must be implemented.
69
New cards
\
What is an interface?
An interface is a data structure that allows you to create a class and outline the methods that other classes that implement it should have.

\
In other words, it sort of allows you to create a blueprint for other classes
70
New cards
\
What is the difference between an interface and an abstract class?
Interfaces cannot be inherited. They are not part of the hierarchy of inheritance between objects. It can only add behavior to a class.

\
Abstract methods on the other hand are part of the hierarchy and can be inherited.
71
New cards
\
What keyword do you use to create an interface?
You use the keyword interface

\
```java
interface {
();
}
```
72
New cards
\
Do you declare method’s scope in an interface?
No, all methods in an interface automatically have a public and abstract scope. These methods simply define the **return type, name,** and **parameters** that classes **implementing** this interface must use, not the **access level.**
73
New cards
How do you declare methods in an interface?
()**;**

\
***Ends with a semicolon!** NO body
74
New cards
\
What keyword do you use to implement an interface in a subclass?
implements

\
```java
public class Circle implements Comparable {}
```

\
75
New cards
\
Do subclasses have to implement all the methods in an interface?
Yes, they must implement every method defined in the interface
76
New cards
\
Can a class implement multiple interfaces?
Yes!
77
New cards
What is the Comparable interface?
An interface that is part of the java.lang package. Has only one method, **compareTo**.
78
New cards
What does compareTo(obj) do?
It returns **0** when the objects are equal, a **negative integer** when obj is less than the object, and a **positive integer** when obj is more than the object
79
New cards
What is an array?
A structure that can store many of the same kind of data at once.

\
For example, an array can store 50 integers, or 10 strings, but it cannot store 20 integers and 10 doubles.
80
New cards
What is a piece of data in an array called?
Elements
81
New cards
What do all elements in an array have?
An index, a special number that shows where the element is in an array.

\
In an array, the index starts at 0.
82
New cards
How do you declare an array?
\[\] = ;

\
= new \[number elements\]

\
\
Or you can do it in one:

\
\[\] name = new \[num of elements\]
83
New cards
Can you put elements into an array during declaration?
Yes, in the declaration instead of just saying the number of elements that will be included you can list the elements.

\
Ex:

\
String\[\] friends = \[“kernit, “Lucille”, “Sammy”, “Roxy”, “Myah”\]
84
New cards
After an array is created, what value is given to each element inside?
The default values of that array type. An array of integers will automatically be 0, an array of strings will automatically be null
85
New cards
How do you access elements in an array?
arrayname\[index\]

\
Ex:

\
System.out.println(friends\[2\])
86
New cards
How are indexes assigned in an array?
The first value of an array has an index of **0**. The index then increases by one as you go through the list. For example, the 5th element will have an index of **4**.
87
New cards
What is ArrayIndexOutOfBounds?
An error generated when you try to access an element in a list with an invalid index.
88
New cards
What does traversing do?
Traversing is the process of access all the elements in the array usually with a **for loop**.

\
Java has a special for loop that differs from the standard 3 part loop for traversing arrays that looks like:

\
for ( name : element)
89
New cards
Can a method have an array for its parameters?
Yes, it’s written like this:

\
public void max(int\[\] num) {}

\
\[\] num

\
Now the max method can receive an array of integer values
90
New cards
What is a linear search?
A way of finding a value in an array by going through **every** single value in the array until the element is found. Can be a bit slow when arrays get very large
91
New cards
What are two dimensional arrays?
Arrays that represent data that corresponds to a grid
92
New cards
How do you declare two dimensional arrays?
\[\]\[\] ;

= new \[num\]\[num\[

\
\*The same as one dimensional arrays but with two brackets
93
New cards
How do you search through elements of a two dimensional array?
You often use a nested for loop
94
New cards
How do you get the length of an array?
name.length
95
New cards
What is the ArrayList class?
A class that allows you to create an ArrayList that has methods to add and delete elements also called a **collections framework.** ArrayLists ONLY hold objects
96
New cards
What are the seven methods of the ArrayList class?
**add(int index, obj element)** Adds something at index

\
**add(obj element)** Adds something to the end of the array

\
**indexOf(obj element**) Gives the index of “element” by using its equals method to compare it to each element in the list

\
**remove(int index)** Removes element at index

\
**set(int index, obj element)** Removes the object at index

\
**size()** Returns number of elements in array
97
New cards
What kind of array is ArrayList?
A dynamic array that can vary in size during run time, and shifts the index of elements when items are added or removed
98
New cards
How do you declare an ArrayList?
ArrayList = new ArrayList();
99
New cards
What happens when you try to store primitive elements in ArrayList?
It will wrap those primitive values in another class to make them objects.

\
For example, primitive int values will be wrapped in the **Integer** class and become an object.

\
Wrapper classes are important because they give each element compareTo or equals() methods that the ArrayList class uses to compare and find values
100
New cards
What does the **String** class do?
It’s a class that handles and manipulates strings.

\
Contains the method: **toCharArray(),** which turns a String object into an array of primitive characters