首页 > 代码库 > 继承类的练习 学习笔记
继承类的练习 学习笔记
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(); } }
继承类的练习 学习笔记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。