刚好,我学到这里啦!!,给你做做,咱俩讨论下!!!
class Person{
//声明变量
private String name;
private int age;
//构造方法
public Person(){}
public Person(String name,int age){
this.name=name;
this.age=age;
}
//setXXX()和getxxx()方法
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;
}
//定义函数
public void sayHello(){
System.out.println("我是"+this.getName()+"今年"+this.getAge());
}
}
class Chinese extends Person{
public Chinese(){}
public Chinese(String name,int age){
super(name,age);
}
}
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
//创建对象
Chinese de=new Chinese();
de.setName("李阳");
de.setAge(21);
de.sayHello();
}
}
[/code] |