下面程序段的输出结果是( )。 public class Test{ public static void main(String args[]){ int X,y; x=(int)Math.sqrt(5)/2+(int)Math.random*5/2; y=(int)Math.sqrt(3)/2+(int)Math.random*3/2; if(x>v) System.OUt.println("x>y"); elseif(x= =y) System.out.println("x=Y"); else System.out.println("x<y"): } }
A.x>y
B.x=Y
C.x<y
D.编译错误
第1题:
如下程序的输出结果是 #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; return 0; }
A.n=0
B.n=1
C.n=2
D. n=3
第2题:
下面程序的输出结果是( )。 #include <iostream> using namespace std; class A { public: A( ) {cout<<"A";} } class B { public: B() {coat<<"B" ;} } class C: public A { public: B b; C() {cout<<"C";} } void mian(){ C c; }
A.CBA
B.ABC
C.ACB
D.BCA
第3题:
下面程序的结果是 ______。 #include<iostream.h> class A{ public: virtual void fun()=0{}; }; class B:public A{ public: void fun () {cout<< "new file" ;} }; class C: public A{ public: void fun (){cout<<"open file"<< " " } }; class D: public A{ public: void fun () {cout<< "save file\n" ;} }; void main() { A a,*p; B b; C c; D d; p=&c; p->fun (); p=&b; p->fun (); p=&d; p->fun(); }
A.new file open file save file
B.new file new file new file
C.编译出错
D.open file new file save file
第4题:
下面程序输出的结果是【 】。
include <iostream>
using namespace std;
class A {
public:
virtual void show() {cout<<"A!";
};
class B: public A {
public:
void show() {cout << "B!";}
};
class C: public B{
public:
void show(){cout << "C!";}
};
void show_info(A &i) {i. show();}
void main() {
A ia; B ib; C ic; show_info(ia);show_info(ib); show_info(ic); }
第5题:
下面程序的结果是 #include<iostream.h> class test{ private: int num; public: test( ); int getint( ) {return num;} ~test( );}; test::test( ) { num=0;} test::~test( ) { cout<<"Destructor is active"<<endl;} void
A.Exiting main Destructor is active Destructor is active Destructor is active
B.Exiting main Destructor is active Destructoris active
C.Exiting main Destructoris active
D.Exiting main
第6题: