-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncapsulationExamples.java
56 lines (45 loc) · 1.14 KB
/
EncapsulationExamples.java
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
51
52
53
54
package Examples;
// Taking example as a Cat
public class EncapsulationExamples {
private int mood = 50;
private int hunger = 50;
private int sleep = 50;
public void play() {
System.out.println("Playing... :)");
mood++;
hunger++;
sleep--;
}
public void feed() {
System.out.println("Feeding...");
hunger--;
sleep++;
mood++;
}
public void sleep() {
System.out.println("Sleeping... x__x");
sleep--;
mood--;
}
public void sound() {
System.out.println("Meowwwwwwwwwwww");
}
public int getMood() {
return mood;
}
public int getHunger() {
return hunger;
}
public int getSleep() {
return sleep;
}
public static void main(String[] args) {
EncapsulationExamples cat = new EncapsulationExamples();
System.out.println("Hunger level is : " + cat.getHunger());
System.out.println("Sleep level is : " + cat.getSleep());
System.out.println("Mood level is : " + cat.getMood());
cat.play();
cat.sleep();
cat.feed();
}
}