Finals Notes III Flashcards

(18 cards)

1
Q

void change(int[] x, int[] y) {
int[] temp = x;
x = y;
y = temp;
x[0] = 99;
}
int[] a = {1, 2, 3};
int[] b = {4, 5, 6};
change(a, b);

Why does this not change?

A

The copies of the REFERENCES are being swapped.
The original values stay the same.

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

What is an object? What does it store?

A
  • Specific instance of a class
  • Has a state (data) and behavior (actions)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the parts of declaring a class?

A

Instance variables, constructors, and methods.

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

What are methods?

A

Getters, setters, etc.

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

What is inheritance?

A

A child class inherits states and behaviors from the parent

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

How do you create a SuperArray object?

A

SuperArray name = new SuperArray()

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

How do you add something to a SuperArray?

A

name.add(“thing”)

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

What does print do for a SuperArray?

A

Prints out everything but null elements.

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

If nothing is given for an index in a SuperArray, what is automatically placed at that index?

A

null

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

What is the code for catching an exception?

A

try { //block of code }
catch { //code executed when exception happens}
finally { //optional }

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

How do you print out the stack trace?

A

e.printStackTrace();

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

What is the variable name commonly placed with an exception while catching?

A

e

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

How do you throw an exception?

A

throw new NameOfException (“Message”)

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

What are some examples of wrapper classes?

A

Boolean, Character, Integer, Double

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

How can you simplify this statement?
Integer y = Integer.valueOf(3);

A

Integer myInt = 3;

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

How do you declare an ArrayList?

A

ArrayList< Type > name = new ArrayList< Type >();

17
Q

How do you import the ArrayList class?

A

import java.util.ArrayList;

18
Q

When do you use an ArrayList over an Array?

A

You do not know how many items you need.
You want to remove or add items to the list.