-
Notifications
You must be signed in to change notification settings - Fork 0
/
AldhiyaCapsul2.java
132 lines (117 loc) · 2.47 KB
/
AldhiyaCapsul2.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class kendaraan
{
private String roda;
private String bahanbakar;
//method input data yang bersifat private
public void sdata(String bb)
{
this.bahanbakar = bb;
}
public void sdat(String bs)
{
this.roda = bs;
}
void berbelok()
{
System.out.println("Sedang berbelok");
}
void berhenti()
{
System.out.println("Sedang berhenti");
}
public void PrintData()
{
System.out.println("Banyak Roda = "+this.roda);
System.out.println("Jenis Bahan Bakar = "+this.bahanbakar);
}
}
class sepedamotor extends kendaraan
{
void maju()
{
System.out.println("Sedang maju");
}
}
class mobil extends kendaraan
{
void mundur()
{
System.out.println("Sedang mundur");
}
}
class truck extends mobil
{
private String berat;
void memutar()
{
System.out.println("Sedang memutar");
}
void mengangkut()
{
System.out.println("Sedang mengangkut");
}
public void dat(String bc)
{
this.berat = bc;
}
public void PrintDat()
{
System.out.println("Berat = "+this.berat);
}
}
public class AldhiyaCapsul2
{
public static void main (String[] args)
{
//pembuatan objek kendaraan
kendaraan k = new kendaraan();
k.sdat("Dua-Tiga-Empat");
k.sdata("BBM");
System.out.println("Objek Kendaraan ----->");
System.out.println("");
k.PrintData();
System.out.println("");
k.berbelok();
k.berhenti();
System.out.println("");
//pembuatan objek sepeda motor
sepedamotor sm = new sepedamotor();
sm.sdat("Dua");
sm.sdata("Premium");
System.out.println("Objek Sepeda Motor ----->");
System.out.println("");
sm.PrintData();
System.out.println("");
sm.berbelok();
sm.berhenti();
sm.maju();
System.out.println("");
//pembuatan objek mobil
mobil m = new mobil();
m.sdat("Empat");
m.sdata("Solar");
System.out.println("Objek Mobil ----->");
System.out.println("");
m.PrintData();
System.out.println("");
m.berbelok();
m.berhenti();
m.mundur();
System.out.println("");
//pembuatan objek kendaraan
truck kt = new truck();
kt.sdat("Enam");
kt.sdata("Pertamax");
kt.dat("2000KG");
System.out.println("Objek Truck ----->");
System.out.println("");
kt.PrintData();
kt.PrintDat();
System.out.println("");
kt.berbelok();
kt.berhenti();
kt.memutar();
kt.mengangkut();
System.out.println("");
}
}