forked from rick2785/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.java
More file actions
50 lines (29 loc) · 913 Bytes
/
Animal.java
File metadata and controls
50 lines (29 loc) · 913 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Animal will act as a Super class for other Animals
public class Animal {
private String name = "Animal";
public String favFood = "Food";
// You use protected when you want to allow subclasses
// To be able to access methods or fields
// If you would have used private their would be no
// way for subclasses to call this method
// This is a final method which means it can't be overwritten
protected final void changeName(String newName){
// this is a reference to the object you're creating
this.name = newName;
}
protected final String getName(){
return this.name;
}
public void eatStuff(){
System.out.println("Yum " + favFood);
}
public void walkAround(){
System.out.println(this.name + " walks around");
}
public Animal(){
}
public Animal(String name, String favFood){
this.changeName(name);
this.favFood = favFood;
}
}