Java中只支持单继承关系
示例代码:
package com.java1995;
public class People {
private String name;
private int age;
private String sex;
//在基类扩展属性,其子类的属性和方法都会被继承,所以说继承易于扩展属性和方法
public void eat(){
System.out.println("人在吃饭");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package com.java1995;
public class Chinese extends People{
public void Speak(){
System.out.println("中国人说汉语");
}
}
package com.java1995;
public class ShanDongPeople extends Chinese {
public void Speak(){
System.out.println("山东人说山东话");
}
}