forked from biblelamp/JavaExercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ1Lesson5.java
More file actions
34 lines (28 loc) · 688 Bytes
/
J1Lesson5.java
File metadata and controls
34 lines (28 loc) · 688 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
class J1Lesson5 {
public static void main(String[] args) {
Cat cat = new Cat("Murzik", "black", 1);
cat.setColor(null);
System.out.println("Cat " + cat.name + " color " + cat.getColor() +
" age " + cat.age + " say " + cat.voice());
}
}
class Cat {
String name;
private String color;
int age;
Cat(String name, String color, int age) {
this.name = name;
this.color = color;
this.age = age;
}
void setColor(String color) {
if (color != null)
this.color = color;
}
String getColor() {
return color;
}
String voice() {
return "meow!";
}
}