单选题public class Item {  private String desc;  public String getDescription() { return desc; }  public void setDescription(String d) { desc = d; } public static void modifyDesc(Item item, String desc) {  item = new Item();  item.setDescription(desc);  }  p

题目
单选题
public class Item {  private String desc;  public String getDescription() { return desc; }  public void setDescription(String d) { desc = d; } public static void modifyDesc(Item item, String desc) {  item = new Item();  item.setDescription(desc);  }  public static void main(String[] args) {  Item it = new Item();  it.setDescription(”Gobstopper”);  Item it2 = new Item();  it2.setDescription(”Fizzylifting”);  modifyDesc(it, “Scrumdiddlyumptious”);  System.out.println(it.getDescription());  System.out.println(it2.getDescription());  }  }  What is the outcome of the code? ()
A

 Compilation fails.

B

 Gobstopper      Fizzylifting

C

 Gobstopper     Scrumdiddlyumptious

D

 Scrumdiddlyumptious     Fizzylifltng

E

 Scrumdiddlyumptious     Scrumdiddlyumptious


相似考题
参考答案和解析
正确答案: C
解析: 暂无解析
更多“public class Item {  private String desc;  public String get”相关问题
  • 第1题:

    为使下列代码正常运行,应该在下画线处填入的选项是( )。 abstract class person{ public Person(String n){ name=n: } Public String getDescription; public String getName{ return name; } private string name; }

    A.static

    B.private

    C.abstract

    D.final


    正确答案:C
    C。【解析】抽象类中的抽象方法可以只声明,定义延迟到其子类。

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

    public class CreditCard {  private String cardlD;  private Integer limit;  public String ownerName;  public void setCardlnformation(String cardlD,  String ownerName, 28. Integer limit) {  this.cardlD = cardlD;  this.ownerName = ownerName;  this.limit = limit;  }  } Which is true?() 

    • A、 The class is fully encapsulated.
    • B、 The code demonstrates polymorphism.
    • C、 The ownerName variable breaks encapsulation.
    • D、 The cardlD and limit variables break polymorphism.
    • E、 The setCardlnformation method breaks encapsulation.

    正确答案:C

  • 第4题:

    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

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

    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

  • 第7题:

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


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

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

     23

    B

     13

    C

     123

    D

     321


    正确答案: 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题:

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

  • 第11题:

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

  • 第12题:

    多选题
    public class Car {  private int wheelCount;  private String vin;  public Car(String vin) {  this.vin = vin;  this.wheelCount = 4;  }  public String drive() {  return “zoom-zoom”;  }  public String getInfo() {  return “VIN: “+ vin + “wheels: “+ wheelCount;  }  }  And:  public class MeGo extends Car {  public MeGo(String vin) {  this.wheelCount = 3;  }  }  What two must the programmer do to correct the compilation errors?()
    A

    insert a call to this() in the Car constructor

    B

    insert a call to this() in the MeGo constructor

    C

    insert a call to super() in the MeGo constructor

    D

    insert a call to super(vin) in the MeGo constructor

    E

    change the wheelCount variable in Car to protected

    F

    change line 3 in the MeGo class to super.wheelCount = 3;


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

  • 第13题:

    阅读以下说明和Java代码,将应填入( )处的字句写在答题纸的对栏内。 【说明】 现如今线下支付系统可以使用现金(Cash)、移动支付、银行卡( Card)(信用卡( Creditcard)和储蓄卡( Debitcard))等多种支付方式( PaymentMethod)对物品(tem)账单(Bill)进行支付。图 5-1 是某支付系统的略类图。

    import java. util. Array List;import java. util. List;interface PaymentMethod { Public ( 1 )}∥cash、 Debitcard和ltem 实现略,ltem中getPrice( )取当前物品对象的价格abstract class Card (2) { private final String name, num; public Card(string name, String num){this.name= name; this, num = num; } @Overide public String toString ( ) { return String. format(“%s card[name = %s, num =%s}”, this. getType( ), name, num); @override public void pay(int cents) { System. out. printin(“Payed"+ cents+"cents using"+toString( )); this, execute Transaction(cents); } protected abstract String getType( ): protected abstract void execute Transaction(int cents)}class CreditCard ( 3 ) { public CreditCard(String name, String num){ (4) ;} @Override protected String getType( ){ return"CREDIT";} @Override protected void execute Transaction(int cents) { System. out. Println(cents +"paid using Credit Card. "); }} Class Bill {//包含所有购买商品的账单 private List items =new ArrayList< >( ); public void add(Item item) { items. add(item): } public intgetTotalPrice( ) {/*计算所有 item 的总价格,代码略*/} public void pay( PaymentMethod paymentMethod) {//用指定的支付方式完成支付(5) (getTotalPrice(): }}public class Paymentsystem { public void pay( ) { Bill bill =new Bill ( ); Item item1 = new Item(1234, 10); Item item2 new Item(“5678”, 40); Bill.add(item1); bill. add(item2);//将物品添加到账单中 Bill.pay(new Creditcard("LI SI”, "98765432101"))∥信用卡支付} public static void main(Stringl args) { (6) = new Paymentsystem( ); payment pay( ); }}


    答案:
    解析:
    (1)void pay(int cents)(2)implements PaymentMethod(3)extends Card(4)super(name, num)(5)paymentMethod.pay(6)Paymentsystem payment
    【解析】

    PaymentMethoc 是个接口,里面的方法在实现类当中进行具体实现,实现类是card和cash,所以第二空填implements PaymentMethoc。在图示中, PaymenuMethoc 中有pay方法,且在实现类中card也有pay方法,所以第一空填void pay( int cents)。第三空填Creditcard类与其他类的关系,可以发现它继承了Card类,所以这里填: extends Card第四空Creditcard内有构造方法,并将方法内的参数传递给父类的私有成员,填:super( name. num)第五空根据传入的paymentMetho象,进行调用pay方法,传入getTotal Price ()的值,所以这里填paymentMethod. pay利用语句 Paymentsystem paymentanew Paymentsystem ( ) 创建一个Paymentsystem类的对象,对象名为payment,然后下面开始调用pay方法。

  • 第14题:

    Which two allow the class Thing to be instantiated using new Thing()?

    • A、 public class Thing { }
    • B、 public class Thing { public Thing() {} }
    • C、 public class Thing { public Thing(void) {} }
    • D、 public class Thing { public Thing(String s) {} }
    • E、 public class Thing { public void Thing() {} public Thing(String s) {} }

    正确答案:A,B

  • 第15题:

    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

  • 第16题:

    public class X {  public X aMethod() { return this;}  }  public class Y extends X {  }  Which two methods can be added to the definition of class Y?()

    • A、 public void aMethod() {}
    • B、 private void aMethod() {}
    • C、 public void aMethod(String s) {}
    • D、 private Y aMethod() { return null; }
    • E、 public X aMethod() { return new Y(); }

    正确答案:C,E

  • 第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 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
    解析: 暂无解析

  • 第19题:

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

  • 第20题:

    单选题
    public class CreditCard {  private String cardlD;  private Integer limit;  public String ownerName;  public void setCardlnformation(String cardlD,  String ownerName, 28. Integer limit) {  this.cardlD = cardlD;  this.ownerName = ownerName;  this.limit = limit;  }  } Which is true?()
    A

     The class is fully encapsulated.

    B

     The code demonstrates polymorphism.

    C

     The ownerName variable breaks encapsulation.

    D

     The cardlD and limit variables break polymorphism.

    E

     The setCardlnformation method breaks encapsulation.


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

  • 第21题:

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


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

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


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

  • 第23题:

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