class Life {
public static void main(String[] args) {
Girl g = new Girl();
g.setName("范冰冰");
g.setAge(25);
g.setGender("女孩");
g.setCountry("中国");
System.out.println("大家好"+","+"我叫"+g.getName()+","+"我今年"+g.getAge()+","+"我是一个特别阳光的"+g.getGender()+","+"我来自美丽的"+g.getCountry() );
g.enter();
g.pursue();
System.out.println();
Boy b = new Boy();
b.setName("李晨");
b.setAge(28);
b.setGender("男孩");
b.setCountry("中国");
System.out.println("大家好"+","+"我叫"+b.getName()+","+"我今年"+b.getAge()+","+"我是一个特别阳光的"+b.getGender()+","+"我也来自美丽的"+b.getCountry() );
b.enter();
b.pursue();
}
}
/*
需求:输出男孩和女孩都应该有各自的人生追求,都应该为自己的理想和目标努力奋斗
分析:
属性:姓名:name,年龄:age,性别:gender,国籍:country
行为:追求,pursue,进入,enter
*/
class Person{
private String name;
private int age;
private String gender;
private String country;
public Person(){}
public Person(String name,int age,String gender,String country ){
this.name = name;
this.age = age;
this.gender = gender;
this.country = country;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
public void setGender(String gender){
this.gender = gender;
}
public String getGender(){
return gender;
}
public void setCountry(String country){
this.country = country;
}
public String getCountry(){
return country;
}
public void enter(){
System.out.println("我们共同进入黑马学习java");
}
public void pursue(){
System.out.println("我们都为自己的理想和目标努力奋斗,黑马加油!");
}
}
class Girl extends Person{
public Girl(){}
public Girl(String name,int age,String gender,String country){
super(name,age,gender,country);
}
}
class Boy extends Person{
public Boy(){}
public Boy(String name,int age,String gender,String country){
super(name,age,gender,country);
}
} |
|