package com.atguigu.exercise;
public class ManKind {
//属性
private int sex;//性别
private int salary;//薪资
//构造器
public ManKind(){
}
public ManKind(int sex,int salary){
this.sex = sex;
this.salary = salary;
}
//方法
public void setSex(int sex){
this.sex = sex;
}
public int getSex(){
return sex;
}
public void setSalary(int salary){
this.salary = salary;
}
public int getSalary(){
return salary;
}
public void manOrWoman(){
if(sex == 1){
System.out.println("man");
}else if(sex == 0){
System.out.println("woman");
}
}
public void employeed(){
if(salary == 0){
System.out.println("no job");
}else if(salary != 0){
System.out.println("job");
}
}
}
package com.atguigu.exercise;
public class Kids extends ManKind{
//属性
private int yearsOld;
//构造器
public Kids(){
}
public Kids(int yearsOld){
this.yearsOld = yearsOld;
}
//方法
public void setYearsOld(int yearsOld){
this.yearsOld = yearsOld;
}
public int getYearsOld(){
return yearsOld;
}
public void printAge(){
System.out.println("I am " + yearsOld + " years old");
}
}
package com.atguigu.exercise;
public class KindsTest {
public static void main(String[] args){
Kids somekid = new Kids(12);
somekid.setSex(1);
somekid.setSalary(0);
somekid.manOrWoman();
somekid.employeed();
somekid.printAge();
}
}