Week 2 Flashcards

1
Q

What are the three principles of Object Oriented Programming (OOP).

A

Encapsulation
* Direct access to components is restricted

Abstraction
* Complexity is reduced
* All but essential details are removed

Inheritance
* Method of deriving one class from another

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

In Java can you have two methods with the same name which differ only by return type.

A

You cannot have two methods with the same name which differ only be return type.

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

Are arrays objects?

Which data types can arrays contain?

A

Arrays are not objects.

Arrays can conatin primitive data types or references to objects.

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

What are the default values for the following:
int
boolean
double/float
char
objects

A
int: 0
boolean: false
double/float: 0.0
char: \u0000 (null character)
objects: null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In Java can you have arrays with different data types?

A

No, you cannot. They must be the same type.

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

In Java create an integer array called implicitLengthArray containing the following values, {1, 2, 3, 5}

A
int[] implicitLengthArray = {1, 2, 3, 5}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Create a dynamically a new array with 3 integers.

A
int[] explicitLengthArray = new int[3];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the following code do?

int[] explicitLengthArray = new int[3];
// Copy an array (by reference)
int[] copyArray = explicitLengthArray;
copyArray[0] = 80000;
System.out.println(explicitLengthArray[0]);
A

This is a copy of by reference. They are referencing the same object, so any changes done may effect the other array.

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

What does the Arrays.copyOfRange do? What do we need to import in order for it to work?

A

We need to
~~~
import java.util.Arrays;
~~~

An example of this is:

char[] originalCharArray = {'a', 'B', 'c', 'D', '5'};

char[] subsetCharArray = Arrays.copyOfRange(originalCharArray, 1, 4);

copyOfRange takes two values, it is inclusive of the first value, but not inclusive of the last value.

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

What are the arguments? What do they do?

System.arraycopy(originalCharArray, 1, subsetCharArray, 0, 2);
A

The arguments are as follows
1. the array to be copied from
2. The index of the original array to start copying from
3. The array being copied to
4. The index of the array being copied to should start
5. The number of elements that should.

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

How do we declare a multidimensional array.

A
String nested[][] = {{"Apple", "Bread", "Corn"}, {"Aardvark", "Buffalo"}}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly