Final Exam

studied byStudied by 1 person
0.0(0)
get a hint
hint

What is top down development?

1 / 100

Tags and Description

101 Terms

1

What is top down development?

A problem solving approach where you break a task down into smaller subtasks

New cards
2

Procedural abstraction

Using methods to define tasks and hide complexity.

New cards
3

2 parts of a method?

Declaration and body

New cards
4

What are the 4 parts of the method declaration?

Access level, return type, name, and parameters

New cards
5

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

New cards
6

What is another word for access level?

Visibility

New cards
7

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.

New cards
8

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.

New cards
9

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.

New cards
10

What happens when you pass an object into a method?

It gives that method a copy of the reference to the object.

New cards
11

How do you separate multiple parameters?

With commas

New cards
12

What is method overloading?

When multiple methods have the same name. The computer differentiates between them by the number and type of their parameters.

New cards
13

What does the return statement do?

Return a value from the method back to the calling statement

New cards
14

What does the keyword void do?

It means that the method doesn’t have to return anything

New cards
15

What are the three parts in a method documentation?

The function, precondition and the post condition

New cards
16

What is the function in method documentation?

It gives a basic overview of what the method does

New cards
17

What is the precondition?

The basic requirements for a method to run. Does not exist for all methods

New cards
18

What is the postcondition?

Describes what is true after the method has been executed

New cards
19

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.

New cards
20

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

New cards
21

What are the two key parts of an object?

Its state and its behavior

New cards
22

What is the state of an object?

The data it stores

New cards
23

What is the behavior of an object?

The actions and communications it provides

New cards
24

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

New cards
25

What is encapsulation/information hiding?

When you protect an objects data by only allowing it to be changed by methods defined by the object

New cards
26

What is a class?

A data type that defines variables and methods for the state and behavior of objects.

New cards
27

What is client code?

An application that uses one or more classes

New cards
28

What is contained in a class declaration?

access level + class + name + {}

ex: public class Circle {}

New cards
29

What goes inside the body of a class?

Variables, constructors and methods

New cards
30

What are members of a class?

The variables and methods in that class

New cards
31

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.

New cards
32

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

New cards
33

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

New cards
34

Are classes always public?

Yes! You can declare it as private, but then nothing else could use it and it would defeat the purpose

New cards
35

Can members of a class be private?

Yes, the variables and methods inside of a class can be private.

New cards
36

What are the three kinds of methods a class can have?

Accessor: Used to determine the value of a variable. Usually named something like getRadius. 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

New cards
37

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.

New cards
38

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.

New cards
39

What are instance methods?

Methods that change the state of an object. This includes accessor and modifier methods

New cards
40

What are class methods?

Methods called from the class itself rather than through an object of that class

New cards
41

What is the object class?

Though objects are all instances of another class, the Object class is the superclass of all classes.

New cards
42

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

New cards
43

What is ClassCastException?

An error thrown when you use the equals method on two noncompatible objects, like a string and int object

New cards
44

Can classes override the equals and toString methods of the object superclass?

Yes, they can override it to better fit their function and purpose

New cards
45

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

New cards
46

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

New cards
47

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

New cards
48

What is polymorphism?

An OOP program features that allows objects to assume different types.

New cards
49

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:

Circle wafer;
Disk cookie = new Disk(2, 0.5);
wafer = cookie; //Wafer began as a circle, now a Disk
New cards
50

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

New cards
51

What is modular programming?

A way of programming where each class are in separate files and can be pieced together or used through objects.

New cards
52

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

New cards
53

How do you extend a class?

Include the keyword extends in the class declaration:

public class (class name) extends (other class name) {}

New cards
54

In inheritance, what can the “top” class that other classes inherit from be called?

The super class, base class, or parent class

New cards
55

In inheritance, what can the “bottom” class that inherits from the parent/base/super class be called?

The derived class, subclass, or child class

New cards
56

What happens when you inherit a class?

You get all of the classes methods and members that were declared public

New cards
57

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

New cards
58

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.

New cards
59

Can a class inherit multiple classes?

No, java only allows a class to inherit one other class.

New cards
60

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

New cards
61

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.

New cards
62

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.

New cards
63

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.

New cards
64

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.

New cards
65

What keyword do you use to create an abstract class?

Abstract

New cards
66

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.

New cards
67

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.

abstract String makeSound();
New cards
68

Do abstract methods have to be implemented in the subclasses that inherit from the abstract class?

Yes, they must be implemented.

New cards
69

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

New cards
70

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.

New cards
71

What keyword do you use to create an interface?

You use the keyword interface

<access_level> interface <name> {
<return_type> <method_name> (<method_parameters>);
}
New cards
72

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.

New cards
73

How do you declare methods in an interface?

()**;**

\
***Ends with a semicolon!** NO body
New cards
74

What keyword do you use to implement an interface in a subclass?

implements

public class Circle implements Comparable {}

New cards
75

Do subclasses have to implement all the methods in an interface?

Yes, they must implement every method defined in the interface

New cards
76

Can a class implement multiple interfaces?

Yes!

New cards
77

What is the Comparable interface?

An interface that is part of the java.lang package. Has only one method, compareTo.

New cards
78

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

New cards
79

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.

New cards
80

What is a piece of data in an array called?

Elements

New cards
81

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.

New cards
82

How do you declare an array?

\[\] = ;

\
= new \[number elements\]

\
\
Or you can do it in one:

\
\[\] name = new \[num of elements\]
New cards
83

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”]

New cards
84

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

New cards
85

How do you access elements in an array?

arrayname[index]

Ex:

System.out.println(friends[2])

New cards
86

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.

New cards
87

What is ArrayIndexOutOfBounds?

An error generated when you try to access an element in a list with an invalid index.

New cards
88

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)
New cards
89

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
New cards
90

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

New cards
91

What are two dimensional arrays?

Arrays that represent data that corresponds to a grid

New cards
92

How do you declare two dimensional arrays?

\[\]\[\] ;

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

\
\*The same as one dimensional arrays but with two brackets
New cards
93

How do you search through elements of a two dimensional array?

You often use a nested for loop

New cards
94

How do you get the length of an array?

name.length

New cards
95

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

New cards
96

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

New cards
97

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

New cards
98

How do you declare an ArrayList?

ArrayList = new ArrayList();
New cards
99

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

New cards
100

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

New cards

Explore top notes

note Note
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 73 people
Updated ... ago
4.0 Stars(2)
note Note
studied byStudied by 47 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 21 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 26 people
Updated ... ago
5.0 Stars(1)

Explore top flashcards

flashcards Flashcard51 terms
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard40 terms
studied byStudied by 31 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard46 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard21 terms
studied byStudied by 14 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard90 terms
studied byStudied by 21 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard20 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
flashcards Flashcard223 terms
studied byStudied by 23 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard27 terms
studied byStudied by 12 people
Updated ... ago
5.0 Stars(1)