第6次Java作业+LSYang

【1】

 1 interface ClassName{
 2     public String getClassName();
 3     }
 4     class Company implements ClassName{
 5         public String getClassName(){
 6         return "Company";
 7     }
 8 }
 9 public class Java6151 {
10     public static void main(String[] args) {
11         ClassName name =new Company();
12         System.out.print(name.getClassName());
13     }
14 }

程序运行结果

 

【4】

 1 class Employer{
 2     private String name;
 3     private int age;
 4     private char sex;
 5     public Employer(){
 6         
 7     }
 8     public Employer(String name,int age,char sex){
 9         super();
10         this.name=name;
11         this.age=age;
12         this.sex=sex;
13     }
14     public String toString(){
15         return "雇员姓名:"+this.name+" 年龄:"+this.age+
16         " 性别:"+this.sex;
17     }
18 }
19 class Manager extends Employer{
20     private String job;
21     private double income;
22     public Manager(){
23         
24     }
25     public Manager(String name,int age,char sex,String job,double income){
26         super(name,age,sex);
27         this.job=job;
28         this.income=income;
29     }
30     public String toString(){
31         return super.toString()+" 职位:"+this.job+" 年薪:"+this.income;
32     }
33 }
34 class Staff extends Employer{
35     private String dept;
36     private double salary;
37     public Staff(){
38         
39     }
40     public Staff(String name,int age,char sex,String dept,double salary){
41         super(name,age,sex);
42         this.dept=dept;
43         this.salary=salary;
44     }
45     public String toString(){
46         return super.toString()+" 部门:"+this.dept+" 月薪:"+this.salary;
47     }
48 }
49 public class Java6154 {
50     public static void main(String[] args) {
51         Employer ea=new Manager("张三",20,'女',"代表",15000.0);
52         Employer eb=new Staff("李四",21,'男',"理事",6000.0);
53         System.out.println(ea);
54         System.out.println(eb);
55     }
56 }

程序运行结果

posted on 2016-04-22 14:14  bgd140201131  阅读(147)  评论(0编辑  收藏  举报