-
给定如下Java程序片断: class A{ public A (){ System.out.println("A"); } } class B extends A{ public B(){ System.out.println("B"); } public static void main(String[] args){ B b=new B(); } } 上述程序将()。
A . 不能通过编译
B . 通过编译,输出为:A B
C . 通过编译,输出为:B
D . 通过编译,输出为:A
-
设有如下程序:public class Test5 {public static void main (String args []) {/* This is the start of a commentif (true) {Test5 = new test5();System.out.println(Done the test);}/* This is another comment */System.out.println (The end);}}结果为?
-
设有类定义如下:class InOut{String s= new String(Between);public void amethod(final int iArgs){int iam=5;iam++;class Bicycle{public void sayHello(){//Here}}}public void another(){ int iOther; }}以下哪些语句可以安排在//Here处 ?
-
设有如下代码public class Test6{int attr[] = {1,2,3};public static void main ( String args[] ) {System.out.println(attr[0]);}}哪个叙述为真?
-
设有如下代码: class Base{} public class MyCast extends Base{ static boolean b1=false; static int i = -1; static double d = 10.1; public static void main(String argv[]){ MyCast m = new MyCast(); Base b = new Base(); //Here } } 则在 //Here处插入哪个代码将不出现编译和运行错误。
-
设有如下程序,其调试结果为:class Q2 {public static void main(String[] args) {int[] seeds = {1,2,3,4,6,8};int n= seeds.length;for (int i = 0; i < 3; i++)for (int k = 0; k< n-1; k++)seeds[k]= seeds[k+1];for (int i = 0; i
-
有如下程序:include<iostream>using namespace std;class MyClass{public:MyClass(int x):val(x
有如下程序: include<iostream> using namespace std; class MyClass{ public: MyClass(int x):val(x){} void Print()const{cout<<“const:val=”<<<val<<‘\’;} void Print(){cout<<“val=”<<val<<‘t’;} private: int va1; }; int main(){ cons
A.val=10 const:val=20
B.const:val=10 const:val=20
C.const:val=10 val=20
D.val=10 val=20
-
有如下程序:include<iostream>using namespace std;class sample{private:int x,y;public:sampl
有如下程序: include<iostream> using namespace std; class sample { private: int x,y; public: sample(int i,int j) { x=i; y=j; } void disp() { cout<<"disp1"<<endl; } void disp()const { cout<<"disp2"<<endl; } }; int main() { const sample a(1,2); a.disp(); return 0; } 该程序运行后的输出结果是()。
A.disp1
B.disp2
C.disp1 disp2
D.程序编译时出错
-
有如下程序:include<iostream)using namespace std;class AA{int n;public:AA(int k):n(k){}int
有如下程序: include<iostream) using namespace std; class AA{ int n; public: AA(int k):n(k){} int get(){return n;} int get()const{return n+1;} }; int main() { AA a(5); const AA b(6); COUt<<A.get()<<b.get(); return 0
A.55
B.57
C.75
D.77
-
有如下程序:include <iostream>using namespace std;class AA {int n;public:AA(int k):n(k) {
有如下程序: include <iostream> using namespace std; class AA { int n; public: AA(int k):n(k) { } int get() {return n;} int get()const {retnm n+1; } int main() { AA a(5); const AA b(6); cout <<a.get()<<b.get(); return 0; }执行后的输出结果是______ 。
A.55
B.57
C.75
D.77
-
有如下程序:includeusing namespace std;Class Test{public:Test(){}Test(const Test&t){co
有如下程序: include using namespace std; Class Test{ public: Test(){} Test(const Test&t){cout<<1;} ); Test fun(Test &u){Test t=u;retum t;} int main(){Test X,y;x=fun(y);retum 0;} 运行这个程序的输出结果是()。
A.无输出
B.1
C.11
D.111
-
有如下程序:include<iostream>using namespace std;class DA{int k;public:DA(int x=1):k(x){}~
有如下程序: include<iostream> using namespace std; class DA{ int k; public: DA(int x=1):k(x){} ~DA(){cout<<k;} }; int main(){ DAd[]={DA(3),DA(3),DA(3)}; DA*p=new DA[2]; delete[]p; return(); } 这个程序的输出结果是()。
A.111
B.333
C.11333
D.11133
-
某java程序的类定义如下: public class MyClass extends BaseClass{ } 则该java源文件在存盘时的源文件名应为
-
有如下程序:include<iostream>using namespace std;class A {public:A(){cout<<"A";}};classB{p
有如下程序: include<iostream> using namespace std; class A { public: A(){cout<<"A";} }; classB{public:B(){cout<<"B";}} classC:public A{ B b; public: C(){cout<<"C";} }; int main(){ C obj; return 0;} 执行后的输出结果是()。
A.CBA
B.BAC
C.ACB
D.ABC
-
有如下程序:include<iostream>using namespace std;class BASE{public:~BASE(){cout<<"BASE";}
有如下程序: include<iostream> using namespace std; class BASE{ public: ~BASE(){cout<<"BASE";} }; class DERIVED:public BASE{ public: ~DERIVED(){cout<<"DERIVED";} }; int main(){DERIVED x;return 0;} 程序的输出结果是
A.BASE
B.DERIVED
C.BASEDERIVED
D.DERIVEDBASE
-
有如下程序:include<iostream>using 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.1111
B.1211
C.1112
D.1212
-
有如下程序 include <iostream> using namespace std; class Base { protected: Base(){cout<<'A'; } Base(char c) { cout<<c; } }; class Derived: public Base { public: Derived(char c){ cout<<c; } }; int main(){ Derived d1 ('B'); return 0; } 执行这个程序屏幕上将显示输出
A.B
B.BA
C.AB
D.BB
-
有如下程序:include<iostream>using namespace std;class A{public:A(){cout<<"A";}~A(){cout<<
有如下程序: include<iostream> using namespace std; class A { public: A(){cout<<"A";} ~A(){cout<<"~A";} }; class B:public A { A*p; public: B(){cout<<"B";p=new A;} ~B(){cout<<"~B";delete p;} }; int main() { B obj; return 0; } 执行这个程序的输出结果是()。
A.BAA~A~B~A
B.ABA~B~A~A
C.BAA~B~A~A
D.ABA~A~B~A
-
有如下程序include<iostream>using namespace std;class base{public:virtual void f1(){cout<<
有如下程序 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<<"F1 Derive"; } void f2(int x) { cout<<"F2 Derive"; } }; int main() { base obj1,*p; derive obj2; p=& obj2; p->f1(); p->f2(); return (); ) 执行后的输出结果是()。
A.F1Derive F2Base
B.F1Derive F2Derive
C.F1Base F2Base
D.F1Base F2Derive
-
若有如下程序:include<iostream>using namespace std;class TestClass{public:void who() {cout
若有如下程序: include<iostream> using namespace std; class TestClass { public: void who() {cout<<"TestClass"<<endl;} }; class TestClass1:public TestClass { public: void who(){cout<<"TestClass1"<<endl;} }; int main() { TestClass *p; TcstClass1 obj1; p=&obj1; p->who(); return 0; } 则该程序运行后的输出结果是()。
A.TestClass1
B.TestClass
C.0
D.无输出
-
有如下程序:include <iostream>using namespace std;class BASE{public:~BASE(){cout<<"BASE";}
有如下程序:include <iostream>using namespace std;class BASE{public: ~BASE(){cout<<"BASE";}};class DERIVED: public BASE{public: ~DERIVED(){ cout<<"DERIVED"; }int main() { DERIVED x; return 0; }执行后的输出结果是()。
A.BASE
B.DERIVED
C.BASEDERIVED
D.DERIVEDBASE
-
有如下程序:include<iostream>using namespace std;class Test{public:Test(){n+=2;}~Test(){n-
有如下程序: include<iostream> using namespace std; class Test{ public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){return n;} private: static int n; }; int Test::n=1; int main() { Test* p=new Test; delete p; cout<<"n="<<Test::getNum()<<endl; return0; } 执行后的输出结果是()。
A.n=0
B.n=1
C.n=2
D.n=3
-
若有如下类声明: class MyClass{ public: MyClass(){cout<<1;}};执行下列语句 MyClass a, b[2], *[2];程序的输出结果是()
A.11
B.111
C.1111
D.11111
-
给定如下Java程序,Test类中的四个输出语句输出结果依次是 。 class Person { String name="person"; public void shout(); } }
A.true,false,true,false
B.false,true,false,false
C.true,true,true,编译错误
D.true,true,false,编译错误