网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
25、在堆栈类StackTest的定义中,为了保证堆栈在并发操作中数据的正确性,应在下划线处填入的代码自上而下分别是________。 public class StackTest{ private int idx = 0; private char[] data = new char[10]; public _____ void push(char c) {……} public______ void pop() {……} }
A.不用填写,synchronized
B.都不用填写
C.synchronized,synchronized
D.synchronized, 不用填写
参考答案和解析
synchronized , synchronized
更多 “25、在堆栈类StackTest的定义中,为了保证堆栈在并发操作中数据的正确性,应在下划线处填入的代码自上而下分别是________。 public class StackTest{ private int idx = 0; private char[] data = new char[10]; public _____ void push(char c) {……} public______ void pop() {……} }A.不用填写,synchronizedB.都不用填写C.synchronized,synchronizedD.synchronized, 不用填写” 相关考题
考题
阅读以下说明C++代码,将应填入(n)处的字句写在对应栏内。[说明]以下程序的功能是实现堆栈的一些基本操作。堆栈类stack共有三个成员函数:empty判断堆栈是否为空;push进行人栈操作;pop进行出栈操作。[C++程序]include "stdafx. h"include <iostream, h>eonst int maxsize = 6;class stack {float data[ maxsize];int top;public:stuck(void);~ stack(void);bool empty(void);void push(float a);float pop(void);};stack: :stack(void){ top =0;cout < < "stack initialized." < < endl;}stack:: ~stack(void) {cout < <" stack destoryed." < < endl;bool stack:: empty (void) {return (1);void stack: :push(float a)if(top= =maxsize) {cout < < "Stack is full!" < < endl;return;data[top] =a;(2);}float stack:: pop (void){ if((3)){cout< < "Stack is undcrflow !" < < endl;return 0;(4);return (5);}void main( ){ stack s;coat < < "now push the data:";for(inti=l;i =maxsize;i+ +) {cout< <i< <" ";s. push(i);}coat < < endl;cout< < "now pop the data:";for(i = 1 ;i < = maxsize ;i + + )cout< <s. pop()< <" ";}
考题
有如下程序: include using namespace std; class Monitor{ public: Monitor(cha
有如下程序:include<iostream>using namespace std;class Monitor{public:Monitor(char t):type(t){ }void Print( )const{cout<<"The type of monitor is"<<type private:char type;};class Computer{public:Computer(int i,char C) :______{}void Print( )const{eout<<"The computer is"<<id<<endl;mort.Print( );}private:int id;Monitor mon;};int main( ){const Computer myComputer(101,'B');myComputer.Print( );return 0;}请将程序补充完整,使程序在运行时输出:The computer is 101The type of monitor is B
考题
为了支持压栈线程与弹栈线程之间的交互与同步,应在下划线处填入的选项是pubIis 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.notify()B.interrupt()C.this .wait()D.sleep()
考题
在下面的类定义中,横线处应填入的内容是 class Fred { public: void print(){cout<<data<<endl;} void setData(double d)(data=d;} static int count; private: double data; }; count=0; //静态数据成员的定义A.intB.static intC.int Fred::D.static int Fred::
考题
( 11 )有如下程序:#includeiostreamusing namespace std;class Monitor{public:Monitor ( char t ) : type ( t ) {}void print ( ) const{cout"The type of monitor is"typeendl;}private:char type;};class Computer{public:Computer ( int i , char c ) : 【 11 】 {}void Print () const{cout"The computer is"idendl;mon.Print ( ) ; }private:int id;Monitor mon;};const Computer myComputer ( 101,'B' ) ;myComputer .Print ( ) ;return 0;}请将程序补充完整,使程序在运行时输出:The computer is 101'The type of monitor i.s 8
考题
( 12 )请将下面的程序补充完整,使得程序输出 “ 飘是张娜的书 ” 。#include iostreamusing namespace std;class Book{public:Book(char *str) {strcpy(title,str);}【 12 】 void PrintInfo() {couttitleendl;}protected:char title[50];};class MyBook:public Book{public:MyBook(char *s1,char *s2= " 张娜 " ):【 13 】 {strcpy(owner,s2);}virtual void PrintInfo() {couttitle " 是 " owner " 的书 " endl;}private:char owner[10];};int main(){Book *prt=new MyBook( " 飘 " );prt-PrintInfo();return 0;}
考题
阅读下列一个支持多线程并发操作的堆栈类代码段 public class MyStack{ private int idx=0; private int[]data=new int[8]; public______void push(int i){ data[idx]=i; idx + +; } …… } 在下画线处应填入的是A.synchronizedB.waitC.blockedD.interrupt
考题
在堆栈类SharedStack的定义中,为了保证堆栈在并发操作中数据的正确性,应在下划线处填入的修饰符是(两个下划线的填写内容相同)public class SharedStack(______int idx=0;______char[]data=new char[10];public synchronized void push(char C) {......}public synchronized void pop{}{......}}A) publicB) 不使用修饰符C) privateD) protectedA.B.C.D.
考题
下列类的定义中,有( ) 处语法错误。 class Base { public: Base(){} Base(int i) { data=i; } private: int data; }; class Derive: public Base { public: Derive(): Base(O) { } Derive(int x) { d=x; } void setvalue(int i) { data=i; } private: d; };A.1B.2C.3D.4
考题
阅读下面一个支持多线程并发操作的堆栈类代码 public class MyStack { private int idx=0; private int[] data=new int[8]; public ______ Void push(int i) { data[idx]=i; idx++; } … } 在下画线处应填入的是A.synchronizedB.waitC.blockedD.interrupt
考题
有以下程序includeincludeusing namespace std;class base{private:charbas
有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[10]; public: base() { strcpy(baseName,"Base"); } virtual char*myName() return baseName; } char *className() { return baseName; } }; class Derived: public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base p) { cout<<p.myName0<<" "<<p.className(); } int main() { base bb; Derived dd; showPtr(dD) ; retum 0; } 动行后的输出结果为A.Derived BaseB.Base BaseC.Derived DerivedD.Base Derived
考题
请将下面的程序补充完整,使得程序输出“飘是张娜的书”。includeusing namespace stdclass Book{public:Book(char*str)|strcpy(title,str);______void Printlnfo(){cout<<title<<endl;}protected:char title[50];};class MyBook:public Book{public:MyBook(char*s1,char*S2=“张娜”):______strcpy(owner,s2);}virtual void PrintInfo(){cout<<title<<“是”<<owner<<“的书”<<endl;}private:charowner[10];};int main(){Book*ptr=new MyBook(“飘”);ptr-Printlnfo();return 0;}
考题
下列类的定义中,有( )处语法错误。 class Base { public: Base(){} Base(int i) { data=i; } private: int data; }; class Derive : public Base { public: Derive() : Base(0) {} Derive (int x) { d=x; } void setvalue(int i) { data=i; } private: d; };A.1B.2C.3D.4
考题
有以下程序include include using namespace std;class base{private:char
有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base () { strcpy(baseName,"Base"); } virtual char *myName() { return baseName; } char *className() { return baseName; } }; class Derived : public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base p) { cout<<p.myName () <<" "<<p.className (); } int main () { base bb; Derived dd; showPtr(dd); return 0; } 运行后的输出结果为A.Derived BaseB.Base BaseC.Derived DerivedD.Base Derived
考题
阅读下面实现堆栈类并发控制的部分代码 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)
考题
为了支持压栈线程与弹栈线程之间的交互与同步,在下画线处依次填入的语句是 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()
考题
在下面的类定义中,横线处应填入的内容是 class Fred { public: void print () { cout<<data<<end1;} void setData (double D) {data=d; static int count; private: double data; };______count=0; //静态数据成员的定义A.intB.static intC.int Fred::D.static int Fred::
考题
有以下程序: #include 〈iostream〉 #include 〈string〉 using namespace std; class visited { private: int number; char *name; public: static int glob; void set mes(char *a); }; void visited::set mes(char *a) { name=new char[strlen(A) +1]; strcpy(name,A) ; number=++glob; } int visited::glob-O; int main() { visited person[10]; int i; char str[8]; for(i=0;i5;i++) { cinstr; person[i] .set mes(str); } coutA.5B.4C.3D.2
考题
有以下程序:include include using namespace std;class Y;class X{private
有以下程序: #include <iostream> #include <string> using namespace std; class Y; class X { private: int x; char *strx; public: X(int a, char *str) { x=a; strx=new char[strlen(str)+1]; strcpy(strx,str); } void show(Y ob) ; }; class Y { private: int y; char *stry; public: Y(int b,char *str) { y=b; stry=new char[strlen(str)+1]; strcpy(stry, str); } friend void X: :show(Y ob) ; }; void X: :show(Y ob) { cout<<strx<<", "; cout<<ob, stry<<end1; } int main ( ) { X a(10,"X"); Y b (20, "Y"); a. show(B) ; return 0; } 执行后的输出结果是( )。A.X,YB.a,bC.X,XD.Y,Y
考题
为了支持压栈线程与弹栈线程之间的交互与同步,应 在下画线处填入的选项是( )。 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
考题
为了支持压栈线程与弹栈线程之间的交互与同步,应在下画线处填入的选项是( )。 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
考题
为了支持压栈线程与弹栈线程之间的交互与同步,在程序的下画线处依次填入的语句是( )。 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
考题
在堆栈类Sharedstack的定义中,为了保证堆栈在并发操作中数据的正确性,应在下画线处填入的修饰符是(两个下画线的填写内容相同)( )。 public class SharedStack{ int idx=0; char[]data=new char[10]; public synchtonized void push(char c){……} publR,synchronized void pop{……} }A.DublicB.不使用修饰符C.privateD.protected
考题
阅读下面实现堆栈类并发控制的部分代码 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)
考题
下列类的定义中,有( )处语法错误。 class Base { public: Base(){} Base(int i) { data=i; } private: int data; }; class Derive : public Base { public: Derive() : Base(O) {} Derive (int x) { d=x; } void setvalue(int i) { data=i; } private: int d; };A.1B.2C.3D.4
考题
有以下程序includeusing namespace std;class Base{private:char c;public:Base(char
有以下程序 #include<iostream> using namespace std; class Base { private: char c; public: Base(char n):c(n){} ~Base() { cout<<c; } }; class Derived:public Base { private: char c; public: Derived(char n):Base(n+1),c(n){} ~Derived() { cout<<c; } }; int main() { Derived obj('x'); return 0; } 执行后的输出结果是A.xyB.yxC.xD.y
考题
( 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()
考题
单选题在堆栈类SharedStack的定义中,为了保证堆栈在并发操作中数据的正确性,应在下划线处填入的修饰符是( )。(两个下划线的填写内容相同)public class SharedStack { ______ int idx = 0; ______ char[] data = new char[10]; public synchronized void push(char c){……} public synchronized void pop(){……}}A
publicB
不使用修饰符C
privateD
protected
热门标签
最新试卷