Subscribe For Free Updates!

We'll not spam mate! We promise.

Pewarisan Java


package javaapplication1;

public class Binatang {
   protected String jenis="jenis";
   protected String makanan="makanan" ;
   public void makan(){
      System.out.println(this.jenis+" makan "+this.makanan);
   }



public class Mamalia extends Binatang {
 public void menyusui(){
  System.out.println(this.jenis + "menyusui");
 }
}
public class Serangga extends Binatang{
 public void terbang(){
  System.out.println(this.jenis+" terbang");
 }
}
public class Monyet extends Mamalia{
 public void manjatPohon(){
  System.out.println(this.jenis+" manjat pohon");
 }
}
public class Anjing {
 public void menggonggong(){
  System.out.println("Ooow...Oooowww...oooww!!!");
 }
}
public class Sapi {
 public void melenguh(){
  System.out.println("OOOOOO.....!!!!!");
 }
}
public class Kupukupu extends Serangga {
 public void metamorfosis(){
  System.out.println(this.jenis+" bermetamorfosis");
 }
}
public class Nyamuk extends Serangga{
 public void bertelur(){
  System.out.println(this.jenis+" bertelur jentik");
 }
}
public class Lebah extends Serangga{
 public void menyengat(){
  System.out.println(this.jenis+" Meyengat");
 }
}
  
}

NB: Bersambung untuk bisa di run

sumber: http://zamzambadruzaman.blog.com/2011/05/17/inheritance-atau-pewarisan-pada-java/

Socializer Widget By Blogger Yard
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 komentar:

Post a Comment