不能通过编译
输出: count 1 = 10 count 2 = 9
输出: count 1 = 9 count 2 = 9
第1题:
下面程序的运行结果是【 】。
inChlde<iOStream>
using namespace std;
class count
{
static int n;
public:
count()
{
n++;
}
static int test()
{
for(int i=0:i<4;i++)
n++;
return n;
}
};
int count::n=0;
int main()
{
cout<<COUnt::test()<<" ";
count c1, c2;
cout<<count::test()<<end1;
return 0;
}
第2题:
如下程序的输出结果是( )。 public class Test { void printValue(int m) { do { System.out.println("The value is"+m); } while( --m>10) } public static void main(String args[]) { int i=10; Test t=new Test(); t.printValue(i); } }
A.The value is 8
B.The value is 9
C.The value is 10
D.The value is 11
第3题:
有如下类定义:
class Test
{
public:
Test(){ a = 0; c = 0;} // ①
int f(int a)const{this->a = a;} // ②
static int g(){return a;} // ③
void h(int
B . {Test::b = b;}; // ④
private:
int a;
static int b;
const int c;
};
int Test::b = 0;
在标注号码的行中,能被正确编译的是
A . ①
B . ②
C . ③
D . ④
第4题:
下列程序的执行结果是 ( ) public class Test { public int aMethod() { satic int i=0; i++; System.out.println(i); } public static void.main(String args[]) { Test test=new Test(); test.aMethod(); }
A.编译错误
B.0
C.1
D.运行成功,但不输出
第5题:
A.t.f
B.this.n
C.Test.m
D.Test.n
第6题:
使用VC6打开考生文件夹下的工程ms9_1,此工程包含一个源程序文件test9_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
4,5
20
源程序文件test9_1.cpp清单如下:
include<iostream.h>
class A
{
protected:
int n,m;
public:
void set(int a,int b){m=a; n=b;)
void show(){cout<<m<<","<<n<<endl;)
/**********found*********/
}
class B:public A
{
int s;
public:
void set(){s=m*n;)
void shows(){cout<<s<<endl;)
};
void main()
{
B b;
/**********found**+******/
b.set();
b.show();
b.set();
/*********found**********/
b.show();
}
第7题:
有如下程序: #include<iostream> using namespace std; Class TestClass { private: int x,y; public: TestClass(int i,int j) { x=i; y=j; } void print() { cout<<“print1”<<endl; } void print()const { cout<<”prin
A.printl
B.print2
C.printl print2
D.程序编译时出错。
第8题:
如下程序的输出结果是______。
include<iostream>
using namespace std;
class pumpkin{
public:
pumpkin( ){++count;}
~pumpkin( ){--eount;}
static void total_count( ){cout<<count<<"pumpkin(s)"<<endl;}
private:
static int count;
};
int pumpkin::count=0;
int main( ){
pumpkin pl[10];
pumpkin::total_count( );
return 0;
}
第9题:
A.public 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.public class
第10题:
如下两个源程序文件,分别编译后,运行Example.class文件,运行结果为______。
AB.java文件代码如下;
package test;
public class AB
{
int a=60;
public void show()
{
System.out.println(”a=”+a);
}
Example.java文件代码如下:
import test.AB;
class Example
{
public static void main(String args[])
{
AB bj=new AB();
obj.show();
}
}