单选题1. public class Employee {  2. String name;  3. double baseSalary;  4. Employee(String name, double baseSalary) {  5. this.name = name;  6. this.baseSalary = baseSalary;  7. }  8. }  And:  1. public class Salesperson extends Employee { 2. double commis

题目
单选题
1. public class Employee {  2. String name;  3. double baseSalary;  4. Employee(String name, double baseSalary) {  5. this.name = name;  6. this.baseSalary = baseSalary;  7. }  8. }  And:  1. public class Salesperson extends Employee { 2. double commission;  3. public Salesperson(String name, double baseSalary,  4. double commission) {  5. // insert code here  6. } 7. }  Which code, inserted at line 7, completes the Salesperson constructor?()
A

 this.commission = commission;

B

 superb(); commission = commission;

C

 this.commission = commission; superb();

D

 super(name, baseSalary); this.commission = commission;

E

 super(); this.commission = commission;

F

 this.commission = commission; super(name, baseSalary);


相似考题

1.阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。[说明]本程序的功能是给公司的员工Tom,Jack,Green增加薪水。三人的职位分别是programmer, Manager,CEO。程序由6个类组成:WorkerTest是主类,programmer,Manager,CEO三个类,薪水增加的规则是 programmer的涨幅是5%;Manager的是10%;CEO也是Manager,但是它除了有Manager的涨幅,还有1000元的bonus。接口SalaryRaise提供了一个增加薪水的方法raise()。[java程序]public class WorkerTest {public WorkerTest( ) {}public static void main( String[] args) {Programmer programmer = new Programmer( "Tom" ,3000);Manager manager = new Manager( "Jack" ,4000);CEO ceo = new CEO( "Green" ,4000);Worker [] worker = new Worker[3];programmer, raise( );manager, raise( );ceo. raise( );worker[0] = programmer;worker [1] = manager;worker[2] = ceo;for ( int i = 0 ;i < worker, length; i + + ) {System. out. prinfln (" Name:" + worker [i]. getName ( ) +" \ tSalary:" + worker [i]. getSalary ());public interface SalaryRaise { void raise( ); }public class Worker {public String name;public double (1);public Worker( ) {}public String getName( ) {return name;}public void setName( String name) {this. name = name;}public double getSalary( ) {return salary;}public void setSalary(double salary) { this. salary = salary; }}public class Programmer extends Worker implements (2) {public Programmer( ) {}public void raise( ) {double pets=0.05;double sala = this. getSalary( ) * (1 + pers);this. setSalary (sala);public Programmer( Siring name, double salary) tthis. name = name;this. salary = salary;public class Manager extends (3) implements SalaryRaise {public Manager( ) { }public Manager(String name, double salary) {this. name = name;this. salary = salary;}public void raise( ) {double pets = 0.1;double sala = this. getSalary() * (1 + pers);this. setSalary(sala);}}public class CEO extends Manager implements SalaryRaise {public CEO() {}public CEO( String name,double salary) {this. name = name;this. salary = salary;}public void raise( ) {double bonus = 1000;(4);double sala = this. getSalary( );(5);this. setSalary(sala);}}

4.试题六(共15分)阅读以下说明和Java代码,填补Java代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。【说明】己知某公司按周给员工发放工资,其工资系统需记录每名员工的员工号、姓名、工资等信息。其中一些员工是正式的,按年薪分周发放(每年按52周计算);另一些员工是计时工,以小时工资为基准,按每周工作小时数核算发放。下面是实现该工资系统的Java代码,其中定义了四个类:工资系统类PayRoll,员工类Employee,正式工类Salaried和计时工类Hourly,Salaried和Hourly是Employee的子类。【Java代码】abstract class Employee{protected String name; //员工姓名protected int empCode; //员工号protected double salary; //周发放工资public Employee(int empCode, String name){this.empCode= empCode;this.name= name;}public double getSalary(){return this.salary;}public abstract void pay();}class Salaried (1) Employee{private double annualSalary;Salaried(int empCode, String name, double payRate){super(empCode, name);this.annualSalary= payRate;}public void pay(){salary= (2) ;//计算正式员工的周发放工资数System.out.println(this.name+":"+this.salary);}}class Hourly (3) Employee{private double hourlyPayRate;private int hours;Hourly(int empCode, String name, int hours, double payRate){super(empCode, name);this.hourlyPayRate= payRate;this.hows= hours,}public void pay(){salary= (4) ;//计算计时工的周发放工资数System.out.println(this.name+":"+this.salary);}}public class PayRoll{private (5) employees[]={new Salaried(l001,"Zhang San", 58000.00),//此处省略对其他职工对象的生成new Hourly(1005,"Li", 12, 50.00)};public void pay(Employee e[]){for (int i=0;i<e.length; i++){e[i].pay();}}public static void main(String[] args){PayRoll payRoll= new PayRoll();payRoll.pay( (6) );double total= 0.0;for (int i=0;i<payRoll.employees.length; i++){//统计周发放工资总额total+=payRoll.employees[i].getSalary();}System.out.println(total);}}

更多“1. public class Employee {  2. String name;  3. double baseS”相关问题
  • 第1题:

    Class TestException  1. public class TestException extends Exception {  2. } Class a:  1. public class a {  2.  3. public String sayHello(String name) throws TestException {  4.  5. if(name == null) {  6. throw new TestException();  7. }  8.  9. return “Hello “+ name;  10. }  11.  12. }  A programmer wants to use this code in an application: 45. A a=new A();  46. System.out.println(a.sayHello(”John”));  Which two are true?()

    • A、 Class a will not compile.
    • B、 Line 46 can throw the unchecked exception TestException.
    • C、 Line 45 can throw the unchecked exception TestException.
    • D、 Line 46 will compile if the enclosing method throws a TestException.
    • E、 Line 46 will compile if enclosed in a try block, where TestException is caught.

    正确答案:D,E

  • 第2题:

    public class Employee{       private String name;  public Employee(String name){           this.name = name;      }  public String getName(){         return name;      } }  public class Manager extends Employee{       public Manager(String name){          System.out.println(getName());      } }  执行语句new Manager(“smith”)后程序的输出是哪项?() 

    • A、 smith
    • B、 null
    • C、 编译错误
    • D、 name

    正确答案:C

  • 第3题:

    1. public class returnIt (  2. returnType methodA(byte x, double y) (  3. return (short) x/y * 2;  4. )  5. )   What is the valid returnType for methodA in line 2?()  

    • A、 Int
    • B、 Byte
    • C、 Long
    • D、 Short
    • E、 Float
    • F、 Double

    正确答案:F

  • 第4题:

    public class Plant {  private String name;  public Plant(String name) { this.name = name; }  public String getName() { return name; }  }  public class Tree extends Plant {  public void growFruit() { }  public void dropLeaves() { }  }  Which is true?() 

    • A、 The code will compile without changes.
    • B、 The code will compile if public Tree() { Plant(); } is added to the Tree class.
    • C、 The code will compile if public Plant() { Tree(); } is added to the Plant class.
    • D、 The code will compile if public Plant() { this(”fern”); } is added to the Plant class.
    • E、 The code will compile if public Plant() { Plant(”fern”); } is added to the Plant class.

    正确答案:D

  • 第5题:

    1. class super {  2. public float getNum() {return 3.0f;}  3. }  4.    5. public class Sub extends Super { 6.   7. }   Which method, placed at line 6, will cause a compiler error?()  

    • A、  Public float getNum()   {return 4.0f; }
    • B、  Public void getNum ()  { }
    • C、  Public void getNum (double d)   { }
    • D、  Public double getNum (float d) {retrun 4.0f; }

    正确答案:B

  • 第6题:

    单选题
    public class Employee{       private String name;  public Employee(String name){           this.name = name;      }  public void display(){         System.out.print(name);      } }  public class Manager extends Employee{       private String department;  public Manager(String name,String department){          super(name);  this.department = department;  }  public void display(){  System.out.println(super.display()+”,”+department);      } }  执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
    A

     smith,SALES

    B

     null,SALES

    C

     smith,null

    D

     null,null

    E

     编译错误


    正确答案: C
    解析: 暂无解析

  • 第7题:

    单选题
    public class Employee{       private String name;  public Employee(String name){           this.name = name;      }  public String getName(){         return name;      } }  public class Manager extends Employee{       private String department;  public Manager(String name,String department){          this.department = department;          super(name);  System.out.println(getName());      }  }  执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
    A

     smith

    B

     null

    C

     SALES

    D

     编译错误


    正确答案: C
    解析: 暂无解析

  • 第8题:

    多选题
    1. class BigDog extends Dog {  2. // insert code here  3. }  分别插入到第 2 行,哪二项可以编译?()
    A

    BigDog() { super(); this(); }

    B

    BigDog() {  String name = Fido;  super();  }

    C

    BigDog() {  super();  String name = Fido;  }

    D

    private BigDog() {  super();}


    正确答案: D,A
    解析: 暂无解析

  • 第9题:

    单选题
    public class Employee{   private String name;   public Employee(String name){   this.name = name;  }   public String getName(){   return name;  }  }   public class Manager extends Employee{   public Manager(String name){   System.out.println(getName());  }  }   执行语句new Manager(“smith”)后程序的输出是哪项?()
    A

     smith

    B

     null

    C

     编译错误

    D

     name


    正确答案: D
    解析: 暂无解析

  • 第10题:

    单选题
    下列选项中,能实现对父类的getSalary方法重写的是(  )。 class Employee{ public double getSalary(){} }
    A

    class Manager extends Employee{
    public int getSalary(double x){}
    }

    B

    class Manager extends Employee{
    public double getSalary(int x,int y){}
    }

    C

    class Manager extends Employee{
    public double getSalary(){}
    }

    D

    class Manager extends Employee{
    public int getSalary(int x,int y){}
    }


    正确答案: A
    解析: 对一个类的继承是指在现有类(父类)的基础上构建一个新类(子类),子类重用(继承)了父类的方法和属性(该属性和方法不能被private修饰),同时还可以向新类中增添新的方法的状态。所以,在子类中可以进行的操作是添加方法。但是不能减少或更换父类的方法。在对父类的方法进行重写的时候,方法的返回值、返回值类型、参数个数、相应的参数类型都要一一对应,所以对父类的getSalary方法重写的时候,返回值的类型应该是double,没有参数。

  • 第11题:

    多选题
    1. public class OuterClass {  2. private double d1 = 1.0;  3. // insert code here  4. }  Which two are valid if inserted at line 3?()
    A

    static class InnerOne { public double methoda() { return d1; } }

    B

    static class InnerOne { static double methoda() { return d1; } }

    C

    private class InnerOne { public double methoda() { return d1; } }

    D

    protected class InnerOne { static double methoda() { return d1; } }

    E

    public abstract class InnerOne { public abstract double methoda(); }


    正确答案: C,A
    解析: 暂无解析

  • 第12题:

    单选题
    public class Employee{   private String name;   public Employee(String name){   this.name = name;  }   public void display(){   System.out.print(name);  }  }   public class Manager extends Employee{   private String department;   public Manager(String name,String department){   super(name);   this.department = department;  }   public void display(){   System.out.println( super.display()+”,”+department);  }   }   执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
    A

     smith,SALES

    B

     null,SALES

    C

     smith,null

    D

     null,null


    正确答案: D
    解析: 暂无解析

  • 第13题:

    1. public class A {  2. public void doit() {  3. }  4. public String doit() {  5. return “a”;  6. }  7. public double doit(int x) {  8. return 1.0;  9. }  10.}  What is the result?() 

    • A、 An exception is thrown at runtime.
    • B、 Compilation fails because of an error in line 7.
    • C、 Compilation fails because of an error in line 4.
    • D、 Compilation succeeds and no runtime errors with class A occur.

    正确答案:C

  • 第14题:

    public class Employee{   private String name;   public Employee(String name){   this.name = name;  }   public void display(){   System.out.print(name);  }  }   public class Manager extends Employee{   private String department;   public Manager(String name,String department){   super(name);   this.department = department;  }   public void display(){   System.out.println( super.display()+”,”+department);  }   }   执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?() 

    • A、 smith,SALES
    • B、 null,SALES
    • C、 smith,null
    • D、 null,null

    正确答案:A

  • 第15题:

    我们定义一个Account类来描述银行账户,银行账户有账户名、金额等属性特征,同时有存款、取款等行为特征,下述代码适合描述的是哪项?()     

    • A、class  Accountf        String name;//账户     S    tring amount;  //金额        Account (String name)(    )   void deposit (double mount){  //存款     )   void withdraw (double mount){  //取款     }     )
    • B、class  Accountf       String name;//账户d  ouole amount;  //金额       Account(double amount){   }  void deposit (double mount){  //存款     )  void withdraw (double mount){  //取款     )     )
    • C、class  Accountf        String name;//账户   double amount;  //金额       Account (String name){}    void deposit (double mount){//存款     )      void withdraw (double mount){  //取款     )     )
    • D、class Accountf        String name;//账户        double amount;//金额      Account (String name){}        void deposit(){//存款     )   void withdraw(){//取款 )     )

    正确答案:C

  • 第16题:

    1. public class OuterClass {  2. private double d1 = 1.0;  3. // insert code here  4. }  Which two are valid if inserted at line 3?()  

    • A、 static class InnerOne { public double methoda() { return d1; } }
    • B、 static class InnerOne { static double methoda() { return d1; } }
    • C、 private class InnerOne { public double methoda() { return d1; } }
    • D、 protected class InnerOne { static double methoda() { return d1; } }
    • E、 public abstract class InnerOne { public abstract double methoda(); }

    正确答案:C,E

  • 第17题:

    11. class Person {  12. String name = “No name‟;  13. public Person(String nm) { name = nm; }  14. }  15.  16. class Employee extends Person {  17. String emplD = “0000”;  18. public Employee(String id) { empID = id; }  19. }  20.  21. public class EmployeeTest {  22. public static void main(String[] args) {  23. Employee e = new Employee(”4321”);  24. System.out.println(e.empID);  25. }  26. }  What is the result?() 

    • A、 4321
    • B、 0000
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 18.

    正确答案:D

  • 第18题:

    多选题
    Class TestException  1. public class TestException extends Exception {  2. } Class a:  1. public class a {  2.  3. public String sayHello(String name) throws TestException {  4.  5. if(name == null) {  6. throw new TestException();  7. }  8.  9. return “Hello “+ name;  10. }  11.  12. }  A programmer wants to use this code in an application: 45. A a=new A();  46. System.out.println(a.sayHello(”John”));  Which two are true?()
    A

    Class a will not compile.

    B

    Line 46 can throw the unchecked exception TestException.

    C

    Line 45 can throw the unchecked exception TestException.

    D

    Line 46 will compile if the enclosing method throws a TestException.

    E

    Line 46 will compile if enclosed in a try block, where TestException is caught.


    正确答案: A,C
    解析: 暂无解析

  • 第19题:

    单选题
    1. public class A {  2. public void doit() {  3. }  4. public String doit() {  5. return “a”;  6. }  7. public double doit(int x) {  8. return 1.0;  9. }  10.}  What is the result?()
    A

     An exception is thrown at runtime.

    B

     Compilation fails because of an error in line 7.

    C

     Compilation fails because of an error in line 4.

    D

     Compilation succeeds and no runtime errors with class A occur.


    正确答案: C
    解析: 暂无解析

  • 第20题:

    单选题
    1. public class Person {  2. private String name;  3. public Person(String name) { this.name = name; }  4. public boolean equals(Person p) {  5. return p.name.equals(this.name);  6. }  7. }  Which is true?()
    A

     The equals method does NOT properly override the Object.equals method.

    B

     Compilation fails because the private attribute p.name cannot be accessed in line 5.

    C

     To work correctly with hash-based data structures, this class must also implement the hashCode method.

    D

     When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.


    正确答案: B
    解析: 暂无解析

  • 第21题:

    单选题
    1. class super {  2. public float getNum() {return 3.0f;}  3. }  4.    5. public class Sub extends Super { 6.   7. }   Which method, placed at line 6, will cause a compiler error?()
    A

      Public float getNum()   {return 4.0f; }

    B

      Public void getNum ()  { }

    C

      Public void getNum (double d)   { }

    D

      Public double getNum (float d) {retrun 4.0f; }


    正确答案: D
    解析: 暂无解析

  • 第22题:

    单选题
    public class Plant {  private String name;  public Plant(String name) { this.name = name; }  public String getName() { return name; }  }  public class Tree extends Plant {  public void growFruit() { }  public void dropLeaves() { }  }  Which is true?()
    A

     The code will compile without changes.

    B

     The code will compile if public Tree() { Plant(); } is added to the Tree class.

    C

     The code will compile if public Plant() { Tree(); } is added to the Plant class.

    D

     The code will compile if public Plant() { this(”fern”); } is added to the Plant class.

    E

     The code will compile if public Plant() { Plant(”fern”); } is added to the Plant class.


    正确答案: A
    解析: 暂无解析

  • 第23题:

    单选题
    1. public class Employee {  2. String name;  3. double baseSalary;  4. Employee(String name, double baseSalary) {  5. this.name = name;  6. this.baseSalary = baseSalary;  7. }  8. }  And:  1. public class Salesperson extends Employee { 2. double commission;  3. public Salesperson(String name, double baseSalary,  4. double commission) {  5. // insert code here  6. } 7. }  Which code, inserted at line 7, completes the Salesperson constructor?()
    A

     this.commission = commission;

    B

     superb(); commission = commission;

    C

     this.commission = commission; superb();

    D

     super(name, baseSalary); this.commission = commission;

    E

     super(); this.commission = commission;

    F

     this.commission = commission; super(name, baseSalary);


    正确答案: C
    解析: 暂无解析

  • 第24题:

    单选题
    public class Employee{   private String name;   public Employee(String name){   this.name = name;  }   public String getName(){   return name;  }  }   public class Manager extends Employee{   private String department;   public Manager(String name,String department){   this.department = department;   super(name); (应于上一行掉位置)   System.out.println(getName());  }  }   Super的位置是否在方法的首行   执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
    A

     smith

    B

     null

    C

     SALES

    D

     编译错误


    正确答案: C
    解析: 暂无解析