-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKonstruktor.java
More file actions
65 lines (53 loc) · 1.33 KB
/
Copy pathKonstruktor.java
File metadata and controls
65 lines (53 loc) · 1.33 KB
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
55
56
57
58
59
60
61
62
63
64
65
// class Player {
// String nama;
// int health;
// int level;
//
// Player(String nama, int health, int level) {
// this.nama = nama;
// this.health = health;
// this.level = level;
//
// System.out.println("Konstruktor di inisialisasi dengan nama:");
// System.out.println(this.nama);
// System.out.println(this.health);
// System.out.println(this.level);
// }
//
// void serang() {
// System.out.println(this.nama + " menyerang");
// }
// }
class Player {
private String nama;
private int health;
public Player(String nama) {
this.nama = nama;
this.health = 100;
}
public void serang() {
System.out.println("player " + nama + " menyerang");
}
public void tampilinData() {
System.out.println("nama: " + nama);
System.out.println("health: " + health);
}
public String getNama() {
return this.nama;
}
public int getHealth() {
return this.health;
}
}
public class Konstruktor {
public static void main(String[] args) {
// Player playerPertama = new Player("arfy", 100, 1);
//
// playerPertama.serang();
Player playerPertama = new Player("james");
playerPertama.tampilinData();
System.out.println(playerPertama.getHealth());
// System.out.println(playerPertama.nama);
// System.out.println(playerPertama.health);
}
}