Java认证考试

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 na

题目

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
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。

[说明]

在一些大型系统中,大多数的功能在初始化时要花费很多时间,如果在启动的时候,所有功能(连不用的功能)都要全面初始化的话,会连带影响到应用软件要花很多时间才能启动。因此常将程序设计成到了实际要使用某种功能的阶段才初始化该功能。

以下示例展示了Proxy(代理)模式,PrinterProxy类执行一些比较“轻”的方法——设置名称和取得名称,需要真正执行“重”的方法——真正打印——时才初始Print类。图6-1显示了各个类间的关系。

[图6-1]

[Java代码]

//Printable.Java

publiC (1) Printable{

public abstract void setPrinterName(String name);

public abstract String getprinterName();

public abstract void print(String string);

}

//Printer.Java

public class Printer implements Printable{

private String name;

public Printer(){

System.out.println("正在产生Printer的对象实例");

}

public Printer(String name){

this.name=name;

heavyJob("正在产生Printer的对象实例("+name+")");

public void setPrinterName(String name){

this.name=name;

public String getPrinterName(){

return name;

public void print(String string){

System.out.println("===" +name+" ====");

System.out.println(string);

}

}

//PrinterProxy.Java

public class PrinterProxy (2) Printable{

private String name;

private Printer real;

public PrinterProxy(){}

public PrinterProxy(String name){

this.name=name;

}

public gynchronized void setPrinterName(String name){

if( (3) ){

real.setPrinterName(name);

}

this.name=name;

}

public String getprinterName(){

return name;

}

public void print(String string){

(4);

real.print(string);

}

private synchronized void realize(){//产生真正的Printer对象

if(real==null){

real=(5);

}

}

}

(1)


正确答案:interface
interface

第2题:

public class Pet{     private String name;     public Pet(){  System.out.print(1);    }  public Pet(String name){        System.out.print(2);    } }  public class Dog extends Pet{     public Dog(String name){        System.out.print(3);    } }  执行new Dog(“棕熊”);后程序输出是哪项?() 

  • A、 23
  • B、 13
  • C、 123
  • D、 321

正确答案:B

第3题:

阅读以下说明和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即可。

第4题:

public class Pet{     private String name;     public Pet(){  System.out.print(1);    }  public Pet(String name){        System.out.print(2);    } }  public class Dog extends Pet{     public Dog(){  System.out.print(4);    }  public Dog(String name){        super(name);  System.out.print(3);    } }  执行new Dog(“棕熊”);后程序输出是哪项?()  

  • A、 33
  • B、 13
  • C、 23
  • D、 123

正确答案:C

第5题:

public class Pet{     private String name;     public Pet(String name){       this.name = name;    }  public void speak(){     System.out.print(name); }  }  public class Dog extends Pet{     public Dog(String name){       super(name);    }  public void speak(){    super.speak();  System.out.print(“ Dog ”);    } }  执行代码   Pet pet = new Dog(“京巴”);  pet.speak();  后输出的内容是哪项?() 

  • A、 京巴
  • B、 京巴 Dog
  • C、 null
  • D、 Dog京巴

正确答案:B

第6题:

执行以下代码后,下面哪些描述是正确的() public  class  Student{  private String name = “Jema”;  public void setName(String name){  this.name = name;  }  public String getName(){  return this.name;  }  public static void main(String[] args){  Student s;  System.out.println(s.getName()); } }

  • A、输出null
  • B、第10行编译报错
  • C、第11行编译报错
  • D、输出Jema

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

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

正确答案:D

第8题:

interface Playable {

void play();

}

interface Bounceable {

void play();

}

interface Rollable extends Playable, Bounceable {

Ball ball = new Ball("PingPang");

}

class Ball implements Rollable {

private String name;

public String getName() {

return name;

}

public Ball(String name) {

this.name = name;

}

public void play() {

ball = new Ball("Football");

System.out.println(ball.getName());

}

}

这个错误不容易发现。


正确答案:

 

错。"interface Rollable extends Playable, Bounceable"没有问题。interface 可继承多个

interfaces,所以这里没错。问题出在interface Rollable 里的"Ball ball = new Ball("PingPang");"。

任何在interface 里声明的interface variable (接口变量,也可称成员变量),默认为public static

final。也就是说"Ball ball = new Ball("PingPang");"实际上是"public static final Ball ball = new

Ball("PingPang");"。在Ball 类的Play()方法中,"ball = new Ball("Football");"改变了ball 的

reference,而这里的ball 来自Rollable interface,Rollable interface 里的ball 是public static final

的,final 的object 是不能被改变reference 的。因此编译器将在"ball = new Ball("Football");"

这里显示有错。

第9题:

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、 编译错误

正确答案:E

第10题:

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、 编译错误

正确答案:D

更多相关问题