import javax.swing.JOptionPane;
class Orang {
String nama = "Noname";
char gender = 'L';
int umur;
void setNama(String n) { //mutator
nama = n;
}
void setGender(char g) {
gender = g;
}
void setUmur(int u) {
umur = u;
}
String getNama() { //accessor
return nama;
}
char getGender() {
return gender;
}
int getUmur() {
return umur;
}
void berjalan() {
System.out.println(nama + " sedang berjalan");
}
}
public class ContohOrang {
public static void main(String[] args) {
Orang orang1 = new Orang();
orang1.nama=JOptionPane.showInputDialog("Enter your name :");
orang1.umur = 64;
System.out.println("Data orang1:");
System.out.println("nama : " + orang1.nama);
System.out.println("gender : " + orang1.gender);
System.out.println("umur : " + orang1.umur);
orang1.berjalan();
Orang orang2 = new Orang();
orang2.setGender('P');
System.out.println("Data orang2:");
System.out.println("nama : " + orang2.getNama());
System.out.println("gender : " + orang2.getGender());
System.out.println("umur : " + orang2.getUmur());
orang2.berjalan();
}
}
2 komentar:
ricco: program bahsa c++ lah cut
ok ok
Ntr aku posTing c++
mksi yah comment nya
Post a Comment