How To Use Class in Java Programming Language
The Following script is the simplest way to declaring and using Class in Java programming language:
class design:
Java program:
class Mahasiswa{ //mahasiswa = student
String Nim; //student#
String Nama; //student name
String Alamat; //student address
void setNim(String Nim){
this.Nim = Nim;
}
String getNim(){
return Nim;
}
void setNama(String Nama){
this.Nama = Nama;
}
String getNama(){
return Nama;
}
void setAlamat(String Alamat){
this.Alamat = Alamat;
}
String getAlamat(){
return Alamat;
}
public static void main(String args[]){
Mahasiswa mhs = new Mahasiswa();
mhs.setNim("007");
mhs.setNama("James Bond");
mhs.setAlamat("Sumedang");
System.out.println(mhs.getNim() +","+ mhs.getNama() +","+ mhs.getAlamat());
}
output:
or you can see the video here:
ShadowOfBdg© - All rights reserved.
No comments:
Post a Comment