JAVA 开发实战经典第六章课后习题答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
ClassName cn = new Company("Company 类") ; System.out.println(cn.getClassName()) ; } }
abstract class Shape{ public abstract float area() ;
} class Triangle extends Shape{
-
return this.income ;
-}
- public String getInfo(){
-
return "管理层信息:" + "\n" +
-
"\t|- 姓名:" + super.getName() + "\n" +
-
"\t|- 年龄:" + super.getAge() + "\n" +
-
- private float salary ;
- public Worker(){}
- public Worker(String name,char sex,int age,String dept,float salary){
-
super(name,sex,age) ;
-
this.setDept(dept) ;
System.out.println(per.getInfo()) ;
}
}
--
--
-
--------------------------------------------------------------------------------------------------------------
this.className = className ; } public String getClassName(){
return this.className ; } } public class ExecDemo01{ public static void main(String args[]){
"\t|- 性别:" + super.getSex() + "\n" +
-
"\t|- 职位:" + this.getJob() + "\n" +
-
"\t|- 年薪:" + this.getIncome() ;
-}
-}
- class Worker extends Employee{
- private String dept ;
this.name = name ; } public void setAddr(String addr){
this.addr = addr ; } public void setSex(char sex){
this.sex = sex ; } public void setAge(int age){
}
public float getEnglish(){
return this.english ;
}
}
public class ExecDemo03{
public static void main(String args[]){
Person per = new Student("张三","北极",'男',30,90.0f,90.0f) ;
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" +
-
this.setSalary(salary) ;
-}
- public String getInfo(){
-
return "员工信息:" + "\n" +
-
"\t|- 姓名:" + super.getName() + "\n" +
-
"\t|- 年龄:" + super.getAge() + "\n" +
-}
- public void setSex(char sex){
-
this.sex = sex ;
-}
- publiຫໍສະໝຸດ Baidu void setAge(int age){
-
this.age = age ;
-}
- public String getName(){
-
return this.name ;
-}
- public char getSex(){
}
public void setMath(float math){
this.math = math ;
}
public void setEnglish(float english){
this.english = english ;
}
public float getMath(){
return this.math ;
} } 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(){
-
this.job = job ;
-}
- public void setIncome(float income){
-
this.income = income ;
-}
- public String getJob(){
-
return this.job ;
-}
- public float getIncome(){
return this.age ; } } class Student extends Person{ private float math ; private float english ; public Student(){} public Student(String name,String addr){
interface ClassName { public String getClassName() ;
} class Company implements ClassName{
private String className ; public Company(){} public Company(String className){
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){
this.age = age ; } public String getName(){
return this.name ; } public String getAddr(){
return this.addr ; } public char getSex(){
return this.sex ; } public int getAge(){
-
"\t|- 性别:" + super.getSex() + "\n" +
-
"\t|- 部门:" + this.getDept() + "\n" +
-
"\t|- 月薪:" + this.getSalary() ;
-}
- public void setDept(String dept){
-
this.dept = dept ;
-
this.setName(name) ;
-
this.setSex(sex) ;
-
this.setAge(age) ;
-}
- public abstract String getInfo() ;
- public void setName(String name){
-
this.name = name ;
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[]){
-
return this.sex ;
-}
- public int getAge(){
-
return this.age ;
-}
-}
-
- class Manager extends Employee{
- private String job ;
- private float income ;
- public Manager(){}
- abstract class Employee{
- private String name ;
- private char sex ;
- private int age ;
- public Employee(){}
- public Employee(String name,char sex,int age){
"\t|- 姓名:" + super.getName() + "\n" + "\t|- 年龄:" + super.getAge() + "\n" + "\t|- 地址:" + super.getAddr() + "\n" + "\t|- 性别:" + super.getSex() + "\n" + "\t|- 数学成绩:" + this.getMath() + "\n" + "\t|- 英语成绩:" + this.getEnglish() ;
- 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){
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 ;
相关文档
最新文档