mirror of
https://github.com/Brandon-Rozek/website.git
synced 2025-10-10 15:01:15 +00:00
Website snapshot
This commit is contained in:
parent
ee0ab66d73
commit
50ec3688a5
281 changed files with 21066 additions and 0 deletions
21
content/ta/fall2017/cpsc220/oct25.md
Normal file
21
content/ta/fall2017/cpsc220/oct25.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Lecture on Oct 25
|
||||
|
||||
## 2 Dimension Array of Objects
|
||||
|
||||
You can not only do a two dimensional array of primitive types, but you can also do two dimensional arrays of objects/classes.
|
||||
|
||||
```java
|
||||
animalLocation[][] map;
|
||||
map = new animalLocation[5][4];
|
||||
```
|
||||
|
||||
Since we are dealing with classes, you cannot use this array right away. The code above creates the space in memory to store the objects. To have the animalLocation objects in the array, you must `new` each instance of the object.
|
||||
|
||||
```java
|
||||
for (int i = 0; i < map.length; i++) {
|
||||
for (int j = 0; j < map[i].length; j++) {
|
||||
map[i][j] = new animalLocation();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue