Rabu, 10 November 2010

Tugas Virtual Class Java

Nama : ABDUL HAMID
NPM : 12108293
Kelas : 3 KA 16


1. SuperKelasKendaraan.java

class SuperKelasKendaraan{
pulic void methodAsli(){
string roda;
string stang;
string sadel;
System.out.println("Method milik SuperKelasKendaraanjalan");
}
public static void jalankan (String[]args){
SuperKelasKendaraanoks=new SuperKelasKendaraan();
oks.methodAsli();
}
void rem (String[]args){
SuperKelasKendaraanoks=new SuperKelasKendaraan();
oks.methodAsli();
}
}

SubKelasMotor.java

class SubKelasMotor extends KelasKendaran{
public void methodAsli(){
System.out.println("method overrided jalan");
}
public void methodJumping(){
roda=2;
System.out.println("kendaraan ber-roda "+roda)
Super.methodAsli();
}
public static void main(String[]args){
Subkelas osk=new SubKelas();
osk.methodASli();
osk.merhodJumping();
}
}


SubKelasMobil.java

class SubKelasMobil extends KelasKendaran{
public void methodAsli(){
System.out.println("method overrided jalan");
}
public void methodMundur(){
roda=4;
System.out.println("kendaraan ber-roda "+roda)
Super.methodAsli();
}
public static void main(String[]args){
Subkelas osk=new SubKelas();
osk.methodASli();
osk.merhodMundur();
}
}
2. Kubus.java

public class Kubus{
private double sisi;//attribute yang di hide
public Kubus(){
sisi=0;
}
private double luas(double s){//encapsulation
return s*s;
}
public void setSisi(double sisi){
this.sisi=sisi;
}
public double getSisi(){
return sisi;
}
Public double getLuas(){
return luas(sisi);
}
}

Tidak ada komentar:

Posting Komentar