根据现实世界的抽象,创建一个多层继承关系的java类,至少两层(不包括继承Object)类中使用 public 、private、static、final 等定义fields和methods
体现组合的重用
体现类之间继承的关系重用
体现override函数和多态的特性
以上为作业要求,如下是自我练习的代码:存在方法声明错误,待纠改
public class Country {
Country country = new Country(); //定义对象country
int filed=960;
String name="中国";
String belongto="Africa";
static String lanuage = "chinese";
//定义方法
public static void speak()
{
System.out.println("中国官方语言是"+lanuage);
System.out.println("外交以及其他重要国际场合通用语言为:");
}
public boolean happyness(String happy)
{
System.out.println("作为中国人幸福吗?"+happy);
return true;
}
class jiangsu extends Country{
public final String character= "教育发达经济繁荣";
public void boss()
{
System.out.println("祖国是:"+name);
}
public void speak(String word) {
Country.speak();
System.out.println("江苏省拥有自己的方言:"+word);
}
}
class shanghai extends Country{
public final String character= "魔都";
}
public void boss()
{
System.out.println("祖国是:"+name);
}
public void speak(String word) {
Country.speak();
System.out.println("上海拥有自己的方言:"+word);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
jiangsu js = new jiangsu();
js.speak("江苏方言");
js.
}
}