class 树 {
// 树的属性
String object;
int age;
int state;
// 构造方法
树() {}
//引用树的object
树(String object) {
//this关键字用来表示树这个类.(的)类变量(属性)object
this.object = object;
}
//树的引进地
void position() {
System.out.println(object + "position");
}
//树的状态
void treestate(int state) {
if (state > 0) {
System.out.print("," + "健康");
}
else {
System.out.print("," + "需要保养");
}
}
//树龄
void treeage(int age) {
System.out.println(",树龄" + age);
}
}
class treewutong
extends 树 {
int state = 1;
int age = 6;
//创建类的构造方法,使之能进行类方法的重载
treewutong() {}
//重载了类的方法,用来处理类对象的属性变量,这里例如object为参数表
treewutong(String object) {
super(object);
}
void position() {
System.out.print(object + "法国引进");
// state(state);
}
}
class treebaiyang
extends 树 {
int state = 0;
int age = 5;
treebaiyang() {}
treebaiyang(String object) {
super(object);
}
void position() {
System.out.print(object + "意大利引进");
}
}
public class tree {
public static void main(String[] args) {
//创建类treewutong的实例 a
treewutong a = new treewutong("梧桐树");
treebaiyang b = new treebaiyang("白杨树");
// 梧桐树的引进位子
a.position();
// 梧桐树的状态
a.treestate(a.state);
// 梧桐树的树龄
a.treeage(a.age);
b.position();
b.treestate(b.state);
b.treeage(b.age);
}
} |
|