




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
interface ClassName public String getClassName() ; class Company implements ClassName private String className ; public Company() public Company(String className) this.className = className ; public String getClassName() return this.className ; public class ExecDemo01 public static void main(String args) ClassName cn = new Company(“Company 类“) ; System.out.println(cn.getClassName(); abstract class Shape public abstract float area() ; class Triangle extends Shape private float foot ; private float height ; public Triangle() public Triangle(float foot,float height) this.setFoot(foot) ; this.setHeight(height) ; public float area() return this.foot * height / 2 ; public void setFoot(float foot) this.foot = foot ; public void setHeight(float height) this.height = height ; public float getFoot() return this.foot ; public float getHeight() return this.height ; class Cycle extends Shape private float radius ; private static final float PI = 3.1415926f ; public Cycle() public Cycle(float radius) this.setRadius(radius) ; public float area() return PI * this.radius * this.radius ; public void setRadius(float radius) this.radius = radius ; public float getRadius() return this.radius; public class ExecDemo02 public static void main(String args) Shape s1 = new Triangle(30.0f,50.6f) ; Shape s2 = new Cycle(25.3f) ; System.out.println(s1.area() ; System.out.println(s2.area() ; abstract class Person private String name ; private String addr ; private char sex ; private int age ; public Person() public Person(String name,String addr) this(name,addr,男,0) ; public Person(String name,String addr,char sex,int age) this.setName(name) ; this.setAddr(addr) ; this.setSex(sex) ; this.setAge(age) ; public abstract String getInfo() ; public void setName(String name) = name ; public void setAddr(String addr) this.addr = addr ; public void setSex(char sex) this.sex = sex ; public void setAge(int age) this.age = age ; public String getName() return ; public String getAddr() return this.addr ; public char getSex() return this.sex ; public int getAge() return this.age ; class Student extends Person private float math ; private float english ; public Student() public Student(String name,String addr) super(name,addr) ; public Student(String name,String addr,char sex,int age,float math,float english) super(name,addr,sex,age) ; this.setMath(math) ; this.setEnglish(english) ; public String getInfo() return“学生信息:“ + “n“ + “t|- 姓名:“ + super.getName() + “n“ + “t|- 年龄:“ + super.getAge() + “n“ + “t|- 地址:“ + super.getAddr() + “n“ + “t|- 性别:“ + super.getSex() + “n“ + “t|- 数学成绩:“ + this.getMath() + “n“ + “t|- 英语成绩:“ + this.getEnglish() ; public void setMath(float math) this.math = math ; public void setEnglish(float english) this.english = english ; public float getMath() return this.math ; public float getEnglish() return this.english ; public class ExecDemo03 public static void main(String args) Person per = new Student(“张三“,“北极“,男,30,90.0f,90.0f) ; System.out.println(per.getInfo() ; - - -abstract class Employee -private String name ; -private char sex ; -private int age ; -public Employee() -public Employee(String name,char sex,int age) -this.setName(name) ; -this.setSex(sex) ; -this.setAge(age) ; - -public abstract String getInfo() ; -public void setName(String name) - = name ; - -public void setSex(char sex) -this.sex = sex ; - -public void setAge(int age) -this.age = age ; - -public String getName() -return ; - -public char getSex() -return this.sex ; - -public int getAge() -return this.age ; - - - -class Manager extends Employee -private String job ; -private float income ; -public Manager() -public Manager(String name,char sex,int age,String job,float income) -super(name,sex,age) ; -this.setJob(job) ; -this.setIncome(income) ; - -public void setJob(String job) -this.job = job ; - -public void setIncome(float income) -this.income = income ; - -public String getJob() -return this.job ; - -public float getIncome() -return this.income ; - -public String getInfo() -return“管理层信息:“ + “n“ + -“t|- 姓名:“ + super.getName() + “n“ + -“t|- 年龄:“ + super.getAge() + “n“ + -“t|- 性别:“ + super.getSex() + “n“ + -“t|- 职位:“ + this.getJob() + “n“ + -“t|- 年薪:“ + this.getIncome() ; - - -class Worker extends Employee -private String dept ; -private float salary ; -public Worker() -public Worker(String name,char sex,int age,String dept,float salary) -super(name,sex,age) ; -this.setDept(dept) ; -this.setSalary(salary) ; - -public String getInfo() -return“员工信息:“ + “n“ + -“t|- 姓名:“ + super.getName() + “n“ + -“t|- 年龄:“ + super.getAge() + “n“ + -“t|- 性别:“ + super.getSex() + “n“ + -“t|- 部门:“ + this.getDept() + “n“ + -“t|- 月薪:“ + this.getSalary() ; - -public void setDept(String dept) -this.dept = dept ; - -public void setSalary(float salary) -this.salary = salary ; - -public String getDept() -return this.dept ; - -public float getSalary() -return this.salary ; - - -public class ExecDemo04 -public static void main(String args) -Employee m = new Manager(“张三“,M,30,“技术主管“,90.0f) ; -Employee w = new Worker(“李四“,F,19,“后勤“,900.0f) ; -System.out.println(m.getInfo() ; -System.out.println(w.getInfo() ; - - - -abstract class Shape -public abstract float area() ; -public abstract float perimeter() ; - -class Triangle extends Shape -private float foot ; -private float height ; -public Triangle() -public Triangle(float foot,float height) -this.setFoot(foot) ; -this.setHeight(height) ; - -public float area() -return this.foot * height / 2 ; - -public float perimeter() -return foot * 3 ; - -public void setFoot(float foot) -this.foot = foot ; - -public void setHeight(float height) -this.height = height ; - -public float getFoot() -return this.foot ; - -public float getHeight() -return this.height ; - - -class Cycle extends Shape -private float radius ; -private static final float PI = 3.1415926f ; -public Cycle() -public Cycle(float radius) -this.setRadius(radius) ; - -public float area() -return PI * this.radius * this.radius ; - -public void setRadius(float radius) -this.radius = radius ; - -public float getRadius() -return this.radius; - -public float perimeter() -return PI * 2 * th
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 上饶卫校面试题及答案
- 排球威力测试题及答案
- 文保员考试试题及答案
- 郑州美术面试题及答案
- 家电公司销售回款管理细则
- 辽宁大连市普兰店区第二中学2026届化学高二第一学期期中经典模拟试题含解析
- 2020-2025年注册测绘师之测绘综合能力模考模拟试题(全优)
- 度第一学期五年级语文期末试卷(人教部编版含答案)
- 保安岗位安全生产培训知识课件
- 医药冻库设备销售方案(3篇)
- 新人教版八年级物理(下册)期末综合能力测试卷及答案
- 低压配电箱安装施工方案
- 中国儿童严重过敏反应诊断与治疗建议(2022年)解读
- 蓄水池检验批质量验收记录(海绵城市质检表格)
- 单梁起重机安全操作培训课件
- 电动力学-同济大学中国大学mooc课后章节答案期末考试题库2023年
- 脑出血诊治指南
- 2022年重庆市汽车运输(集团)有限责任公司招聘考试真题
- 结构方案论证会汇报模板参考83P
- 移植患者健康宣教 - 副本课件
- 魏家庄村道路实施方案
评论
0/150
提交评论