消除下述代码 compile 阶段语法错误的方式为 class A { public: virtual int f() = 0; }; int main() { A a; (a) -> f(); }A.将第3行代码中的virtual关键字去掉B.将第3行代码中的 = 0; 改为 {}C.将第6行及第7行代码删除D.将第7行改为 a.f();E.将第3行代码中的 = 0 去掉
消除下述代码 compile 阶段语法错误的方式为 class A { public: virtual int f() = 0; }; int main() { A a; (&a) -> f(); }
A.将第3行代码中的virtual关键字去掉
B.将第3行代码中的 = 0; 改为 {}
C.将第6行及第7行代码删除
D.将第7行改为 a.f();
E.将第3行代码中的 = 0 去掉
参考答案和解析
将第3行代码中的 = 0; 改为 {};将第6行及第7行代码删除;将第3行代码中的 = 0 去掉
相关考题:
有如下程序:#includeusing namespace std;class ONE{public:virtual void f(){cout"l";}};class TWO:public ONE{public:TWO(){cout"2";}};class THREE:public TWO{public:virtual void f(){TWO::f(); cout"3";}};int main(){ONE aa, *p;TWO bb;THREE cc;p = cc;p-f();return 0;}执行上面程序的输出是 【 11 】 。
有如下程序: include using namespaee std; class ONE{ public: virtual void f 有如下程序:include <iostream>using namespaee std;class ONE{public:virtual void f( ){cout<<"1";}};class TWO:public ONE{public:TWO( )1 cout<<"2";}{;class THREE:public TWO{public:virtual void f( )}TWO::f( );cout<<"3";}};int main( ){ONE aa,*P;TWO bb;THREE cc;P=cc;p->f( );return 0;}程序的输出结果是______。
有如下程序: include using namespace std; class A { public: virtual void f(){cout 有如下程序:include<iostream>using namespace std;class A{public:virtual void f(){cout<<"1";}};class B:public A{public:B (){cout<<"2";}};class C:public B{public:virtual void f(){B::f();cout<<"3";}};int main(){A aa,*p;B bb;C cc;p=cc;p->f();return 0;}执行上面程序的输出是______。
( 32 )有如下程序:#includeiostreamUsing namespace std;class A{public:virtual void f () {cout+1;}void g () {cout2;}};class B:public A{public:virtual void f () {cout3;}void g () {ecut4;}};void show ( A a ) {a.f ( ) ; a.g ( ) ; }int main () {B b;show ( b ) ;return 0;}运行时的输出结果是A ) 12B ) 34C ) 14D ) 32
下面代码段的输出结果为( )。 public class Test { public static void main(String sss[]) { int i=0xFFFFFFFl; int j=~i; } }A.0B.1C.14D.-15
有如下程序:includeusing namespaee std;class VAC{public:int f( )COUSt{return 3;} 有如下程序: #include<iostream> using namespaee std; class VAC{ public: int f( )COUSt{return 3;} int f( ){return 5;} }; int main( ){ VAC vl; const VAC v2; eout<<v1.f( )<<v2.f( ); return 0; } 程序的输出结果是A.53B.35C.55D.33
有如下程序:includeusing namespace std;class GA{public:virtual int f( ){return 1 有如下程序: #include<iostream> using namespace std; class GA{ public: virtual int f( ){return 1;} }; class GB:public GA{ public: virtual int f( ){return 2;} }; void show(GA g){eout<<g.f( );} void display(GA&g){cout<<g.f( );} int main( ){ GA a;show(A) ;display(A) ; GB b;show(B) ;display(B) ; return 0; } 程序的输出结果是A.1111B.1211C.1112D.1212
有如下程序:includeusing namespace std;class XX{protected:int k;public:XX(int n= 有如下程序: #include<iostream> using namespace std; class XX { protected: int k; public: XX(int n=5):k(n){}; ~XX() { cout<<"XX": } virtual void f()const=0; }; inline void XX::f()const { cout<<k+3; }; class YY:public XX { public: ~YY() { cout<<”YY”; } void f()const { cout<<k-3; XX::f(); } }; int main() { XX p=*new YY; P.f(); delete p; return 0: } 执行上面的程序将输出( )。A.28XXB.28YYXXC.33XXD.33XXYY
下列代码的执行结果是( )。 public class Test { public static void main ( String args[]) { float f=5.0f; int i=4; System.out.println((f++) *(--i)); } }A.20B.20.0C.15D.15.0
已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?() A.t.fB.this.nC.Test.mD.Test.n
有以下程序:include using namespace std;class Base{public: Base(){} virtual void 有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void f1() { cout<<"f1 of base"<<end1; } ~Base(){} }; class Derive: public Base { public: void fl(int x) { cout<<"f1 of derive"<<end1; } }; int main ( ) { Base *p; Derive obj1; p=obj 1; p->f1 ( ); return 0; }A.编译时出错B.f1 of deriveC.f1 of baseD.以上答案都不对
有如下程序: include using namespace std; class base { public:virtual void f1(){ 有如下程序: #include<iostream> using namespace std; class base { public: virtual void f1() { cout<<"F1Base"; } virtual void f2() { cout<<"F2Base "; } }; class derive : public base { void f1 ( ) { cout<<"F1Derive"; } void f2( int x ) { cout<<"F2 Derive"; } }; int main () { base objl, * p; derive obj2; p = obj2; p -> f1(); p -> f2(); return 0; } 执行后的输出结果是( )。A.F1Derive F2BaseB.F1Derive F2DeriveC.F1Base F2BaseD.F1Base F2Derive
下列程序的输出结果是【 】。includeiostreamusing namespace std;class Base{int x;public:Base(int b):x(b){}virtual void display(){coutx;}};class Derired:public Base{int y;public:Derived(int d):Base(d),y(d){}void display(){couty;}};int main(){Base b(1);Derived d(2);Base*p=d;b.display();d.display();p-display();return 0;}
下面程序的输出结果是【】。include using namespace std; class base { protected: int 下面程序的输出结果是【 】。include <iostream>using namespace std;class base{protected:int a;public:base(){cout<<"0":}};class basel: virtual public base{public:base1(){ cout<<"1";}};class base2 : virtual public base{public:base2(){cout<<"2";}};class derived : public base1,public base2{public:derived () {cout<<"3"; }}int main (){derived obj;cout<<end1;return 0;}
有如下程序:includeusing namespace std;class XX{protected;int k;public:XX(int n= 有如下程序: #include<iostream> using namespace std; class XX{ protected; int k; public: XX(int n=5):k(n){} ~XX(){cout<<"XX";} Virtual void f()cons=0; }; inline void XX::f()const{cout<<k+3;} class YY:public XX{ public:A.28XXB.28YYXXC.-33XXD.-33XXYY
在下列源代码文件Test.java中,正确定义类的代码是( )。A.pblic class test { public int x=0; public test(int x) { this. x=x;} }B.public class Test { public int x=0; public Test(int x) { this. x=x;} }C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }
下列代码执行结果为 ( )public class Test{ public static void main(String args[]){ float p=0f; int q=3; System.out.println(++p)*(q--)); }}A.16B.24C.16D.24
有如下程序:#includeiostrealnusing namespace stdclass A{public:virtual void f(){cout1;}void g(){cout2;}};class B:public A{public:virtual void f(){cout3;}void g(){cout4;)};void show(AA){a.f();a.g();}int main(){B b;show(B);return 0;}运行时的输出结果是A.12B.34C.14D.32
请问下述代码中: int operator+(…)起什么作用?this 是什么?ccc 的值最终为多少?class Fruit{public:Fruit(){weight = 2;}Fruit(int w){weight = w;}int operator+(Fruit f){return this-weight * f.weight;}private:int weight;};Fruit aaa;Fruit bbb(4);int ccc = aaa + bbb;
若有以下程序:include using namespace std;class Base {public:Base() { x=0; } int 若有以下程序: #include <iostream> using namespace std; class Base { public: Base() { x=0; } int x; }; class Derivedl: virtual public Base { public: Derivedl() { x=10; } }; class Derived2: virtual public Base { public: Derived2() ( x=20; } }; class Derived: public Derivedl,protected Derived2 { }; int main() { Derived obj; cout<<obj.x<<end1; return 0; } 该程序运行后的输出结果是A.20B.30C.10D.0
有如下程序: inClude using namespace std; class AA { public: viltual void f() { c 有如下程序:inClude<iostream>using namespace std;class AA{public:viltual void f(){cout<<"AA";}};class BB:public AA{public:BB(){cout<<"BB";}};class CC:public BB{public:virtual void f(){BB::f();cout<<"CC";}};int main(){AA aa,*p;BB bb;CC cc;p=cc;p->f();return 0;}运行后的输出结果【 】。
有如下程序: #includeiostream using namespace std; class GA{ public: virtual int ft retum l;} }; class GB:public GA{ public: virtual int f{retum 2;} }; void show(GA g){eout9.f;} void display(GAg){cout9.f;} int main { GA a;show(A.;display(A.; GB b;show(B.;display(B.; return 0; } 执行这个程序的输出结果是( )。A.1111B.1211C.1112D.1212
执行以下程序后,输出结果为public class ex2{public static void main(String args[]) {int f=1;int k;for (k=2;k A. 0B. 1C. 5D. 4E. 24
阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。 【说明】以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。【C++代码】#include #include using namespace std;class DrawCircle { //绘制圆形,抽象类 public: (1) ;//定义参数为 int radius, int x, int y virtual~DrawCircle() { }}; class RedCircle:public DrawCircle { //绘制红色圆形 public: void drawCircle(int radius, int x, int y) { cout drawCircle = drawCircle; } virtual~shape() { } public: virtual void draw() = 0;}; class Circle:public Shape { //圆形 private: int x,y,radius; public: Circle(int x,int y,int radius,DrawCircle *drawCircle) (3) { this->x = x; this->y = y; this->radius = radius; } public: void draw() { drawCircle -> (4) ; }}; int main(){ Shape *redCircle=new Circle(100,100,10, (5) );//绘制红色圆形 Shape *greenCircle=new Circle(100,100,10, (6) );//绘制绿色圆形 redCircle ->draw(); greenCircle ->draw(); return 0;}
阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。【说明】以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。【C++代码】#include?#include?using?namespace?std;class?DrawCircle?{??????//绘制圆形,抽象类? ? ? public: (1);//定义参数为?int?radius,?int?x,?inty? ?virtual~DrawCircle()?{?}};class?RedCircle:public?DrawCircle?{????//绘制红色圆形? ? ? ? public: void?drawCircle(intradius,?int?x,?int?y)?{cout??drawCircle?=?drawCircle;? }? ?virtual~shape()?{?}? public:? ?virtual?void?draw()?=?0;};class?Circle:public?Shape?{????//圆形? ? private:? ? ?int?x,y,radius;? ? public:? Circle(int?x,inty,int?radius,DrawCircle?*drawCircle)? (3)? {? this->x?=?x;? ?this->y?=?y;? ? this->radius?=?radius; }? ? ? public:? void?draw(){? drawCircle?-> (4); }};int?main(){Shape?*redCirclenew?Circle(100,100,10,????(5)????);//绘制红色圆形? Shape?*greenCircle=new?Circle(100,100,10, (6)??);//绘制绿色圆形redCircle >draw();? ?greenCircle?->draw();? ?return?0;}
What will be the result of attempting to compile and run the following code?() public class Q6b0c { public static void main(String args[]) { int i = 4; float f = 4.3; double d = 1.8; int c = 0; if (i == f) c++; if (((int) (f + d)) == ((int) f + (int) d)) c += 2; System.out.println(c); } } A、The code will fail to compile.B、0 will be written to the standard output.C、1 will be written to the standard output.D、2 will be written to the standard output.E、3 will be written to the standard output.
1. public class Blip { 2. protected int blipvert(int x) { return 0; } 3. } 4. class Vert extends Blip { 5. // insert code here 6. } Which five methods, inserted independently at line 5, will compile?() A、 public int blipvert(int x) { return 0; }B、 private int blipvert(int x) { return 0; }C、 private int blipvert(long x) { return 0; }D、 protected long blipvert(int x, int y) { return 0; }E、 protected int blipvert(long x) { return 0; }F、 protected long blipvert(long x) { return 0; }G、protected long blipvert(int x) { return 0; }
单选题What will be the result of attempting to compile and run the following code?() public class Q6b0c { public static void main(String args[]) { int i = 4; float f = 4.3; double d = 1.8; int c = 0; if (i == f) c++; if (((int) (f + d)) == ((int) f + (int) d)) c += 2; System.out.println(c); } }AThe code will fail to compile.B0 will be written to the standard output.C1 will be written to the standard output.D2 will be written to the standard output.E3 will be written to the standard output.