niusouti.com

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

相似考题

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

2.阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。[说明]在一些大型系统中,大多数的功能在初始化时要花费很多时间,如果在启动的时候,所有功能(连不用的功能)都要全面初始化的话,会连带影响到应用软件要花很多时间才能启动。因此常将程序设计成到了实际要使用某种功能的阶段才初始化该功能。以下示例展示了Proxy(代理)模式,PrinterProxy类执行一些比较“轻”的方法——设置名称和取得名称,需要真正执行“重”的方法——真正打印——时才初始Print类。图6-1显示了各个类间的关系。[图6-1][Java代码]//Printable.JavapubliC (1) Printable{public abstract void setPrinterName(String name);public abstract String getprinterName();public abstract void print(String string);}//Printer.Javapublic 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.Javapublic 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)

更多“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 nam”相关问题
  • 第1题:

    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

  • 第2题:

    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

  • 第3题:

    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

  • 第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(String name){   //这里隐藏了一句代码:super.pet();   System.out.print(3);  }   }   执行new Dog(“棕熊”);后程序输出是哪项?() 

    • A、 23
    • B、 1 3
    • C、 123
    • D、 321

    正确答案:B

  • 第5题:

    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

  • 第6题:

    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

  • 第7题:

    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

  • 第8题:

    单选题
    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){        this();  System.out.print(3);    } }  执行new Dog(“棕熊”);后程序输出是哪项?()
    A

     143

    B

     423

    C

     243

    D

     1134


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

  • 第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

     编译错误


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

  • 第10题:

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


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

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    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){   //这里隐藏了一句代码:super.pet();   System.out.print(3);  }   }   执行new Dog(“棕熊”);后程序输出是哪项?()
    A

     23

    B

     1 3

    C

     123

    D

     321


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

  • 第13题:

    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

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

    正确答案:E

  • 第15题:

    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

  • 第16题:

    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.pet();   this();   System.out.print(3);  }  }   执行new Dog(“棕熊”);后程序输出是哪项?() 

    • A、 143
    • B、 423
    • C、 243
    • D、 1134

    正确答案:A

  • 第17题:

    Given the following code:     1) class Parent {     2) private String name;     3) public Parent(){}     4) }  5) public class Child extends Parent {     6) private String department;  7) public Child() {}  8) public String getValue(){ return name; }     9) public static void main(String arg[]) {     10) Parent p = new Parent();     11) }  12) }  Which line will cause error?()   

    • A、 line 3
    • B、 line 6
    • C、 line 7
    • D、 line 8
    • E、 line 10

    正确答案:D

  • 第18题:

    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){        this();  System.out.print(3);    } }  执行new Dog(“棕熊”);后程序输出是哪项?()  

    • A、 143
    • B、 423
    • C、 243
    • D、 1134

    正确答案:A

  • 第19题:

    public class NamedCounter {  private final String name;  private int count;  public NamedCounter(String name) { this.name = name; }  public String getName() { return name; }  public void increment() { coount++; }  public int getCount() { return count; } public void reset() { count = 0; } }  Which three changes should be made to adapt this class to be used safely by multiple threads? ()

    • A、 declare reset() using the synchronized keyword
    • B、 declare getName() using the synchronized keyword
    • C、 declare getCount() using the synchronized keyword
    • D、 declare the constructor using the synchronized keyword
    • E、 declare increment() using the synchronized keyword

    正确答案:A,C,E

  • 第20题:

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


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

  • 第21题:

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


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

  • 第22题:

    单选题
    Given the following code:     1) class Parent {     2) private String name;     3) public Parent(){}     4) }  5) public class Child extends Parent {     6) private String department;  7) public Child() {}  8) public String getValue(){ return name; }     9) public static void main(String arg[]) {     10) Parent p = new Parent();     11) }  12) }  Which line will cause error?()
    A

     line 3

    B

     line 6

    C

     line 7

    D

     line 8

    E

     line 10


    正确答案: D
    解析: 第8行的getValue()试图访问父类的私有变量,错误。

  • 第23题:

    单选题
    执行以下代码后,下面哪些描述是正确的() 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


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