package com.ctgu.java; public class ManKind { private int sex; private int salary; public int getSex() { return sex; } public void setSex(int sex) { this.sex = sex; } public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } public void manOrWomen(){ if(sex == 1) System.out.println("Man"); else if(sex == 0) System.out.println("Women"); else System.out.println("你输入的有误"); } public void employees(){ if(salary == 0) System.out.println("no job"); else if(salary > 0) System.out.println("job"); } }
package com.ctgu.java; public class Kids extends ManKind { private int yearsOld; public int getYearsOld() { return yearsOld; } public void setYearsOld(int yearsOld) { this.yearsOld = yearsOld; } public void printAge(){ System.out.println(this.yearsOld + " years old "); } }
package com.ctgu.java; public class TestKids { public static void main(String[] args) { Kids someKids = new Kids(); someKids.setSalary(10); someKids.setSex(1); someKids.setYearsOld(13); someKids.employees(); someKids.manOrWomen(); someKids.printAge(); } }
时间: 2024-11-02 11:06:23