




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024秋八年级英语上册 Unit 4 What's the best movie theater Section A(1a-2d)说课稿(新版)人教新目标版
- 店铺转让的合同
- 2025版一年期租房合同范本:一年房屋租赁合同模板
- 水果采购合同
- 新教材高中化学 1.2.2 离子反应说课稿 新人教版必修1
- 技术开发委托合同
- 苏州市劳动合同5篇
- 2025翡翠交易合同范本
- 2025年股权让与反担保合同
- 考点解析人教版八年级上册物理《机械运动》专题测试试题(含详细解析)
- 2025年机械工程师职称考试题及参考答案
- 护理专业科普
- EHS风险管理监测规范制定
- Unit 2 We are Family.单元测试( 含答案)2025-2026学年人教版(2024)英语七年级上册
- 2025“文化强国杯”全国高校文学知识挑战赛备赛试题库150题(含答案)
- 一科一品护理服务
- 中燃集团工程物资供应商管理制度
- 小学食品安全培训课件
- 项目立项申请表
- 机械基础 第2版 习题答案
- 2025发展对象考试题库附含答案
评论
0/150
提交评论