public class planet {
//planet name
private String namaPlanet;
//total moon per planet
private int jmlBulan;
//revolution and rotation
private double jmlRotasi, jmlRevolusi;
public planet(String namaPlanet, int jmlBulan, double jmlJamPhari, double jmlHariPtahun) {
this.namaPlanet = namaPlanet;
this.jmlBulan = jmlBulan;
this.jmlRotasi = jmlJamPhari;
this.jmlRevolusi = jmlHariPtahun;
}
public planet(String namaPlanet, double jmlRotasi, double jmlRevolusi) {
this.namaPlanet = namaPlanet;
this.jmlRotasi = jmlRotasi;
this.jmlRevolusi = jmlRevolusi;
}
}
月亮课:
public class bulan extends planet {
private String namaBulan;
public bulan(String namaBulan, String namaPlanet,double jmlJamPhari, double jmlHariPtahun) {
super(namaPlanet, jmlJamPhari, jmlHariPtahun);
this.namaBulan = namaBulan;
}
}
答案 0 :(得分:1)
由于月亮不是一颗行星,你不应该从星球上获得你的月球类,而应该给月球一个行星的参考和/或让行星有一个卫星列表。
public class Moon {
private String name;
private Planet planet;
public Moon(String name, Planet planet) {
this.name = name;
this.planet = planet;
}
}