contoh implements,extends, dan method di java

share untuk pemula java…:D
class Bumi.java

public class Bumi implements TataSurya{

private String name;
private int rotasi;

public Bumi(String name){
this.name = name;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
@Override
public int getRotasi(){
return rotasi;
}
@Override
public void setRotasi(int rotasi){
this.rotasi = rotasi;
}

}

class Bulan.java

public class Bulan extends Bumi{

private int besar;
private int rotasi = 5;

public Bulan(int besar,String name){
super(name);
this.besar = besar;
}
public void setBesar(int besar){
this.besar = besar;
}
public int getBesar(){
return besar;
}

@Override
public int getRotasi(){
return rotasi;
}

}

class TataSurya.java

public interface TataSurya{
void setRotasi(int rotasi);
int getRotasi();

}

class CallAll.java

public class CallAll{
public static void main(String[] args){
Bulan m = new Bulan(2 , “mymoon”);
System.out.println(m.getBesar()+ ” ” + m.getName() + ” ” +m.getRotasi());
}
}

hohoho…udah selesai…….lagi gak mute..jadi nulis asal..:D

2 thoughts on “contoh implements,extends, dan method di java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s