class Account {   private int balance;   public void setBalance(int b) { balance = b; }  public int getBalance() { return balance; }   public void clearBalance() { balance = 0; }   }   哪一个改变可以使 Account 类线程安全?() A、在第2行加 synchronized 修饰符。B、在第3行加 synchronized 修饰符。C、在第3行、第4行和第6行加 synchronized 修饰符。D、在第4行、第6行和第8行加 synchronized 修饰符。

class Account {   private int balance;   public void setBalance(int b) { balance = b; }  public int getBalance() { return balance; }   public void clearBalance() { balance = 0; }   }   哪一个改变可以使 Account 类线程安全?() 

  • A、在第2行加 synchronized 修饰符。
  • B、在第3行加 synchronized 修饰符。
  • C、在第3行、第4行和第6行加 synchronized 修饰符。
  • D、在第4行、第6行和第8行加 synchronized 修饰符。

相关考题:

下面这个程序的结果是includeclass A{private:int a;public:void seta();int geta( 下面这个程序的结果是 #include<iostream.h> class A { private: int a; public: void seta();int geta();}; void A∷seta() {a=1;} int A∷geta() {return a;} class B { pnvate: int a; publiC: void sera();int geta();}; void B∷seta() {a = 2;} int B∷geta() {return a;} class C:public A,public B { private: int b; public: void display();}; void C∷display() { int b=geta(); cout<<b;} void main() { C c; c.seta(); c.display();}A.1B.2C.随机输出1或2D.程序有错

已知如下类定义: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正确地加入子类中?() A.private void fun( int n ){ //...}B.void fun ( int n ){ //... }C.protected void fun ( int n ) { //... }D.public void fun ( int n ) { //... }

classAccount{privateintbalance;publicvoidsetBalance(intb){balance=b;}publicintgetBalance(){returnbalance;}publicvoidclearBalance(){balance=0;}}哪一个改变可以使Account类线程安全?() A.在第2行加synchronized修饰符。B.在第3行加synchronized修饰符。C.在第3行、第4行和第6行加synchronized修饰符。D.在第4行、第6行和第8行加synchronized修饰符。

若有以下程序 include using namespace std; class A {private:int a; public: A(in 若有以下程序 #include <iostream> using namespace std; class A { private: int a; public: A(int i) { a=i; } void disp() { cout<<a<<","; } }; class B { private: int b; public: B(int j) { b=j; } void disp() { cout<<b<<","; } }; class C: public B,public A { private: int c; public: C(int k):A(k-2),B(k+2) { c=k; } void disp() { A::disp(); B::disp(); cout<<c<<end1; } }; int main() { C obj(10); obj.disp(); return 0; } 程序执行后的输出结果是A.10,10,10B.10,12,14C.8,10,12D.8,12,10

下面这个程序的结果是 include class A { private: int a; public: void seta( ) ; 下面这个程序的结果是#include<iostream.h>class A{private:int a;public:void seta( ) ;int geta( ) ;};void A: :seta( ){ a=1;}int A: :geta( ){ retum a;}class B{ private:int a;public:void seta( ) ;int geta( ) ;};void B: :seta( ){a=2;}int B: :geta( ){return a;}class C: public A,public B{ private:int b;public:void display( ) ;};void C: :display( ){ int b=geta( ) ;cout < < b;}void main( ){ C c;c. seta( ) ;c. display( ) ;}A.1B.2C.随机输出1或2D.程序有错

有以下程序:include using namespace std;class A{private:int a;public:A (int i){a 有以下程序: #include <iostream> using namespace std; class A { private: int a; public: A (int i) { a=i; } void disp() { cout<<a<<","; } }; class B { private: int b; public: B(int j) { b=j; } void disp() { cout<<b<<","; } }; class C : public B,public A { private: int c; public: C(int k) :A(k-2),B(k+2) { c=k; } void disp () { A::disp (); B::disp (); cout<<c<<endl; } }; int main () { C obi (10); obj.disp (); return 0; } 程序执行后的输出结果是A.10,10,10B.10,12,14C.8,10,12D.8,12,10

阅读下面实现堆栈类并发控制的部分代码 public class DataStack{ private int idx=0; private int[]data=new int[8]; public void push(int i){ . ________________{ data[idx]=i; idx + +; } } } …… } 在程序下画线处填入正确选项是A.synchronizedB.synchronized(this)C.synchronized()D.synchronized(idx)

若有以下程序:include using namespace std;class A{private:int a;public:A(im i){a 若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: A(im i) { a=i; } void disp() cout<<a<<","; } }; class B { private: int b; public: B(int j) { b=j; } void disp0 { cout<<b<<","; } }; class C: public B,public A { private: int c; public: C(int k):A(k-2),B(k+2) { c=k; } void disp0 { A::disp(); B::disp(); cout<<c<<endl; } }; int main() { C obj(10); obj.disp(); return 0; } 程序执行后的输出结果是( )。A.10,10,10B.10,12,14C.8,10,12D.8,12,10

为了支持压栈线程与弹栈线程之间的交互与同步,在下画线处依次填入的语句是 public class IntStack { private int idx=0; private int[]data=new int[8]; public ______ void push(int i) { data[idx]=i; idx++; ______ } … }A.synchronized() notify()B.synchronized() this.wait()C.synchronized() this.notify()D.synchronized() sleep()

若有以下程序:includeusing namespace std;class A{private:int a; public:void seta 若有以下程序: #include<iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb(int x) { b=x; } void showb() { cout<<b<<",”; } }; class C:pUblic A,private B { private: int c; public: void setc(int x,int y,int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; } }; int main() { Cc; c.setc(1,2,3); c.showc(); retrun 0; } 程序执行后的输出结果是A.1,2,3B.1,1,1C.2,2,2D.3,3,3

若有以下程序:includeusing namespace std;class A{private:inta;public:voidseta(in 若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb (int x) { b=x; } void showb() { cout<<b<<","; } }; class C :public A,private B { private: int c; public: void setc(int x, inc y, int z) { c=z; seta (x); setb (y); } void showc() { showa (); showb (); cout<<c<<end1; } }; int main () { C c; c. setc(1,2,3); c.showc(); return 0; } 程序执行后的输出结果是A.1,2,3B.1,1,1C.2,2,2D.3,3,3

若有以下程序:include using namespace std;class A{private:int a;public:A(int i){ 若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: A(int i) { a=i; } void disp () { cout<<a<<","; } }; class B { private: int b; public: B(int j) { b=j; } void disp () { cout<<b<<","; } }; class C : public B,public A { private: int c; public: C(int k):A(k-2),B(k+2) { c=k; } void disp () { A::disp(); B::disp(); cout<<c<<endl; } }; int main() { C obj(10); obj.disp(); return 0; }A.10,10,10B.10,12,14C.8,10,12D.8,12,10

若有以下程序:include using namespace std;class A{private:int a;public:void seta 若有以下程序:#include <iostream>using namespace std;class A{private: int a;public: void seta(int x) { a=x; } void showa() { cout<<a<<","; }};class B{private: int b;public: void setb(int x) { b=x; } void showb() { cout<<b<<","; }};class C: public A, private B{private: int c;public: void setc(int x, int y, int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; }};int main(){ C c; c.setc(1,2,3); c.showc(); return 0;}程序执行后的输出结果是( )。A.1,2,3B.1,1,1C.2,2,2D.3,3,3

为了支持压栈线程与弹栈线程之间的交互与同步,应 在下画线处填入的选项是( )。 public class StackTest{ private int idx=0; private int[]data=new int[8] public void push(int i){ synchronized(this){ ; data(idx)=i: idx++: } } }……A.this.notifyB.interruptC.this.waitD.sleep

现有人编写了帐号类Account,用于管理个人的存款余额, public Account{ private double balance; //帐号余额,余额最低为0 public double getBalance(){ return balance; } Public void setBalance(double b){ balance=b; } public double withdrawl(double money) throws Exception { //取款,money如果为负数或余额不足,抛出异常 } } 请用错误推测法为withdrawl()函数至少设计3个测试用例,并写出基于Junit的测试代码 。

为了支持压栈线程与弹栈线程之间的交互与同步,在程序的下画线处依次填入的语句是( )。 public class IntStack{ private int idx=0; private int[]data=new int[8]; public void push(int i){ data[idx]=i: idx++; … … }A.synchronized notifyB.synchronized this.waitC.synchronized this.notifyD.Serializable sleep

阅读下面实现堆栈类并发控制的部分代码 public class DataStack } private int idx=0; private int[] data=new int[8]; public void push(int i) { ______ { data[idx]=I: idx++; } } … } 程序中下画线处应填入的正确选项是A.synchronizedB.synchronized(this)C.synchronized()D.synchronized(idx)

若有以下程序:includeusing namespace std;class A{private:int x;public:int z;void 若有以下程序:#include<iostream>using namespace std;class A {private: int x;public: int z; void setx(int i) { x=i; } int getx () { return x; }}:class B : public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a) ; z=b; m=c; } void display{) { cout<<getx ()<<", "<<z<<", "<<m<<end1; }};int main(){ B obj; obj. setvalue(2,3,4); obj.display(); return 0;} 程序运行以后的输出结果是A.产生语法错误B.2,3,4C.2,2,2D.4,3,2

( 31 ) 为了支持压栈线程与弹栈线程之间的交互与同步 , 在程序的下划线处依次填入的语句是public class IntStack{private int idx=0;private int[] data=new int[8];public void push(int i){data[idx]=i;idx++;}__________......}A ) synchronized()notify()B ) synchronized()this.wait()C ) synchronized()this.notify()D ) synchronized()sleep()

给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A } A、public int cal(int x,int y,float z){return 0;}B、public int cal(int x,int y,int z){return 0;}C、public void cal(int x,int z){}D、public viod cal(int z,int y,int x){}

public class SyncTest {  private int x;  private int y;  private synchronized void setX( int i ) { x = i; }  private synchronized void setY( int i ) { y = i; }  public void setXY( int i ) { setX(i); setY(i); }  public synchronized boolean check() { return x != y; }  }   Under which condition 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 return true only if SyncTest is changed to allow x and y to be set separately.

public class MethodOver  {  public void setVar (int a, int b, float c)  {  }  }   Which two overload the setVar method?()  A、 Private void setVar (int a, float c, int b)  { }B、 Protected void setVar (int a, int b, float c) { }C、 Public int setVar (int a, float c, int b) (return a;)D、 Public int setVar (int a, int b, float c) (return a;)E、 Protected float setVar (int a, int b, float c) (return c;)

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 keywordB、 declare getName() using the synchronized keywordC、 declare getCount() using the synchronized keywordD、 declare the constructor using the synchronized keywordE、 declare increment() using the synchronized keyword

public class SyncTest {  private int x;  private int y;  public synchronized void setX (int i) (x=1;)  public synchronized void setY (int i) (y=1;)  public synchronized 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 set separately.

public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()A、 public class Circle implements Shape { private int radius; }B、 public abstract class Circle extends Shape { private int radius; }C、 public class Circle extends Shape { private int radius; public void draw(); }D、 public abstract class Circle implements Shape { private int radius; public void draw(); }E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

多选题public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()Apublic class Circle implements Shape { private int radius; }Bpublic abstract class Circle extends Shape { private int radius; }Cpublic class Circle extends Shape { private int radius; public void draw(); }Dpublic abstract class Circle implements Shape { private int radius; public void draw(); }Epublic class Circle extends Shape { private int radius;public void draw() {/* code here */} }Fpublic abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

单选题class Account {   private int balance;   public void setBalance(int b) { balance = b; }  public int getBalance() { return balance; }   public void clearBalance() { balance = 0; }   }   哪一个改变可以使 Account 类线程安全?()A在第2行加 synchronized 修饰符。B在第3行加 synchronized 修饰符。C在第3行、第4行和第6行加 synchronized 修饰符。D在第4行、第6行和第8行加 synchronized 修饰符。