题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2023-12-01 06:21:56

[单项选择] public class MyLogger {  private StringBuilder logger = new StringBuuilder();  public void log(String message, String user) {  logger.append(message);  logger.append(user);  }  }  The programmer must guarantee that a single MyLogger object works properly for a multi-threaded system. How must this code be changed to be thread-safe?() 
A.  synchronize the log method
B.  replace StringBuilder with StringBuffer
C.  No change is necessary, the current MyLogger code is already thread-safe.
D.  replace StringBuilder with just a String object and use the string concatenation (+=) within the log method

更多"public class MyLogger&ens"的相关试题:

[多项选择] public class TestDemo{   private int x = 2;   static int y = 3;   public void method(){   final int i=100;   int j = 10;   class Cinner{   public void mymethod(){  //Here  }  }  }  }   在Here处可以访问的变量是哪些?()
A. x
B. y
C. i
D. j
[单项选择] 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
[单项选择] public class SyncTest (  private int x;  private int y;  private synchronized void setX (int i) (x=1;)  private synchronized void setY (int i) (y=1;)  public void setXY(int 1)(set X(i); setY(i);)  public synchronized Boolean check() (return x !=y;)  )  Under which conditions will check () return true when called from a different class?   
A.  Check() can never return true.
B.  Check() can return true when setXY is called by multiple threads.
C.  Check() can return true when multiple threads call setX and setY separately.
D.  Check() can only return true if SyncTest is changed to allow x and y to be setseparately.
[单项选择] public class ItemTest {  private final mt id;  public ItemTest(int id) { this.id = id; }  public void updateId(int newId) { id = newId; }  public static void main(String[] args) {  ItemTest fa = new ItemTest(42);  fa.updateId(69);  System.out.println(fa.id);  }  }  What is the result?() 
A.  Compilation fails.
B.  An exception is thrown at runtime.
C.  The attribute id in the Item object remains unchanged.
D.  The attribute id in the Item object is modified to the new value.
E.  A new Item object is created with the preferred value in the id attribute.
[多项选择] public class TestFive {  private int x;  public void foo() {  int current = x;  x = current + 1;  }  public void go() {  for(int i=0;i<5;i++) {  new Thread() {  public void run() {  foo();  System.out.print(x + “, “);  } }.start();  }}}  Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()
A.  Move the line 12 print statement into the foo() method.
B.  Change line 7 to public synchronized void go() {.
C.  Change the variable declaration on line 3 to private volatile int x;.
D.  Wrap the code inside the foo() method with a synchronized( this ) block.
E.  Wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.
[单项选择] 1. class Test {  2. private Demo d;  3. void start() {  4. d = new Demo();  5. this.takeDemo(d); 6. }  7.   8. void takeDemo(Demo demo) {  9. demo = null;  10. demo = new Demo(); 11. }  12. }  When is the Demo object, created on line 3, eligible for garbage collection?()  
A.  After line 5.
B.  After line 9.
C.  After the start() method completes.
D.  When the takeDemo() method completes.
E.  When the instance running this code is made eligible for garbage collection.
[多项选择]                         下列解释正确的是()
A. out_applet.java中一定有一个参数是“display_string” 
B. 具有两个属性“name”和“value” 
C. value是参数的名称 
D. “good morning”通过 标记传递给“Our_Applet.class”
[简答题] 一般程序如下:                ORG  2000H      ARY      DW   --4,3,--2,1   CNT      DW   $--ARY   VAR      DW   ARY,$+4          ┆           MOV  AX,ARY              MOV  BX,OFFSET VAR               MOV  CX,CNT               MOV  DX,VAR+2              LEA  SI,ARY            ┆   此程序段执行后,寄存器AX,BX,CX,DX与SI中的内容各是多少? 
[单项选择] 现有:      1  Interface F{}  2  class A implements F{}      3  class B extends A{}      4  class C extends B{  5    public static void main(String[]  args){      6    B b=new B();  7    //inSert C0de here      8    }      9    } 下列哪行代码插入到第7行,将抛出java.lang.ClassCaseException异常()
A.    A a=b;
B.   F f=  (C)b;
C.   F f=  (A)b;
D.   B bb=  (B)(A)b;
[单项选择] 现有:     class Pencil  {  public void write (String content){     System.out.println ("Write"+content);     }     }  class RubberPencil extends Pencil{     public void erase (String content){     System.out.println ("Erase"+content);     }     }  执行下列代码的结果是哪项?()      Pencil pen=new RubberPencil();      pen.write ("Hello");      pen.erase ("Hello");    
A.  Write Hello        Erase Hello
B.  Erase Hello        Write Hello
C. 编译错误
D. 运行时抛出异常
[多项选择]  public class Foo {   private int val;   public foo(int v) (val = v;) }   public static void main (String args) {   Foo a = new Foo (10);   Foo b = new Foo (10);   Foo c = a;   int d = 10;   double e = 10.0;   }   Which three logical expression evaluate to true? ()
A.  (a ==c)
B.  (d ==e)
C.  (b ==d)
D.  (a ==b)
E.  (b ==c)
F.  (d ==10.0)
[单项选择] 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

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码