-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDoggie.java
More file actions
33 lines (26 loc) · 725 Bytes
/
Doggie.java
File metadata and controls
33 lines (26 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Doggie {
private String name;
public static void main(String[] args) {
Doggie dog1 = new Doggie();
dog1.name = "Bart";
dog1.bark();
Doggie[] myDogs = new Doggie[3];
myDogs[0] = new Doggie();
myDogs[1] = new Doggie();
myDogs[2] = dog1;
myDogs[0].name = "Fred";
myDogs[1].name = "Jorge";
System.out.print("Last dog name - ");
System.out.println(myDogs[2].name);
int x = 0;
while (x < myDogs.length) {
myDogs[x].bark();
x = x + 1;
}
}
private void bark() {
System.out.println(name + " said woof!");
}
void eat() {}
void chaseCat() {}
}