单选题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题:

阅读和理解下面程序段: class Manager extends Employee{ public Manager(String n,double s,int year,int month,int day){ super(n,s,year,month,day); bonus=0; } public double getSalary(){ double baseSalary-super.gerSalary(); return baseSalary+bonus; } public void setBonus(double b){bonus=b; ) private double bonus; } Manager是Employee的子类,其理由是( )。

A.Manager的适用范围较宽

B.extends关键字声明

C.Manager的域减小了

D.雇员是一个经理


正确答案:B
解析:本题考查Java中子类的概念。Java中通过在类声明中加入extends子句来创建子类,格式为:class SubClass extens SuperClass{…}。题目中class Manager extends Employee语句定义Manager类为Employee类的子类,所以选项B是正确答案。Manager类定义了Manager(String n,double s,int year,int month,int day)、getSalary()和setBonus(double b)成员方法和bonus成员变量。

第2题:

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);

正确答案:D

第3题:

1.publicclassEmployee{2.Stringname;3.doublebaseSalary;4.Employee(Stringname,doublebaseSalary){5.this.name=name;6.this.baseSalary=baseSalary;7.}8.}And:1.publicclassSalespersonextendsEmployee{2.doublecommission;3.publicSalesperson(Stringname,doublebaseSalary,4.doublecommission){5.//insertcodehere6.}7.}Whichcode,insertedatline7,completestheSalespersonconstructor?()

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);


参考答案:D

第4题:

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.

正确答案:A

第5题:

1. public interface A {  2. public void doSomething(String thing);  3. }  1. public class AImpl implements A {  2. public void doSomething(String msg) { }  3. }  1. public class B {  2. public A doit() {  3. // more code here  4. }  5.  6. public String execute() { 7. // more code here  8. }  9. }  1. public class C extends B {  2. public AImpl doit() {  3. // more code here  4. }  5.  6. public Object execute() {  7. // more code here  8. }  9. }  Which statement is true about the classes and interfaces in the exhibit?() 

  • A、 Compilation will succeed for all classes and interfaces.
  • B、 Compilation of class C will fail because of an error in line 2.
  • C、 Compilation of class C will fail because of an error in line 6.
  • D、 Compilation of class AImpl will fail because of an error in line 2.

正确答案:C

第6题:

试题六(共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)extends
(2)annualSalary/52
(3)extends
(4)hours*hourlyPayRate
(5)~(6)的解答可为以下两种之一:
(5)Employee
(6)payRoll.employees

(5)staticEmployee
(6)employees或payRoll.employees

第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());  }  }   Super的位置是否在方法的首行   执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()

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

正确答案:D

第8题:

阅读以下说明和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) t

this. 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);

}

}


正确答案:(1)salary (2)SalaryRalse (3)Worker (4) super. raise() (5)sala+=bonus及其等效形式
(1)salary (2)SalaryRalse (3)Worker (4) super. raise() (5)sala+=bonus及其等效形式 解析:(1)从Worker这个类的结构来看,它有两个属性ufinle和salary,因此这里应该填salary;
(2)~(3):很显然Programmer类和Manager类继承于 Worker类和SalaryRaise接口。
(4)~(5):CEO类继承于Manager类,而根据题意, CEO除了有Managor的涨幅,还有1000元的bonus。所以,CEO薪水的涨幅可以使用基类相同的方法super. raise(),然后再加上奖金sala+=bonus即可。

第9题:

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

第10题:

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

更多相关问题