下列程序的输出结果是( )。 public class Test { public static void main(String[] args) { char a1 = 'B', a2 = 'c'; if(a1+1<a2) ++a1; System.out.println(a1); } }
A.B
B.b
C.C
D.c
第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>
include <string>
using namespace std;
class Y;
class X
{
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
{
prlvate:
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<<endl;
}
int main{
{
X a (10, "stringX");
Y b (20, "stringY");
a. show (b);
renurn 0;
}
第3题:
下列程序的输出结果是______。 #include<iostream> using namespace std; class Test( public: Test() {cnt++;} ~Test() {cnt--;} static int Count(){return cnt;} private: static int cnt; }; int Test::cnt=0; int main() { cout<<Test::Count()<<""; Test t1,t2; Test*pT3=new Test; Test*pT4=new Test; cout<<Test::Count()<<""; delete pT4; delete pT3; cout<<Test::Count()<<end1; return 0; }
A.024
B.042
C.420
D.240
第4题:
下列程序的运行结果是______。
include<iostream.h>
class Base
{
public:
void f(int x){cout<<“Base:”<<x<<endl;}
);
class Derived:public Base
{
public:
void f(char*str){cout<<“Derived:”<<str<<endl;}
};
void main(void)
{
Base*pd=ne
第5题:
有如下程序: #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
第6题: