编译如下Java程序片断: class test{ int count = 9; public void a(){ int count=10; System.out.println("count 1 =" + count); } public void count(){ System.out.println("count 2 =" + count); } public static void main(String args[]){ test t=new test(); t.a(); t.count(); } } 结果将()。
第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题:
编译如下Java程序片断:classtest{intcount=9;publicvoida(){intcount=10;System.out.println("count1="+count);}publicvoidcount(){System.out.println("count2="+count);}publicstaticvoidmain(Stringargs[]){testt=newtest();t.a();t.count();}}结果将()。
A.不能通过编译
B.输出: count1=10 count2=9
C.输出:count1=9 count2=9
第4题:
有如下程序: #include using name space std; classB{ public: B(int xx):x(xx){++count;x+=10;} virtual void show()const {cout<<count<<'_'<<x<<endl;} protected: static int count; private: intx; }; class D:publicB{ public: D(int xx,int yy):B(xx),y(yy){++count;y+=100;} virtual void show()const {cout<<count<<'_'<<y<endl}; pnvate: inty; }; int B::count=0; intmain(){ B*ptr=new D(10,20); ptr->show(); delete ptr; return 0; } 运行时的输出结果是( )。
A.1_120
B.2_120
C.1_20
D.2_20
第5题:
( 35 )有如下程序:
#include <iostream>
using namespace std;
Class B{
public:
B(int xx):x(xx) {++cout; x+=10;}
virtual void show() const
{cout<<count<< ' _ ' <<x<<endl;}
protected:
static int count;
private:
int x;
};
class D:public B{
public:
D(int xx,int yy):B(xx),y(yy) {++count; y+=100;}
virtual void show() const
{cout<<count<< ' _ ' <<y<<endl;}
private:
int y;
};
int B::count=0;
int main(){
B *ptr=new D(10,20);
ptr->show();
delete ptr;
return 0;
}
运行时的输出结果是
A ) 1_120
B ) 2_120
C ) 1_20
D ) 2_20
第6题:
下列程序段的输出结果是【 】。
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);
}
}
第7题:
下面程序的正确输出是( )。 public class Hello { public static void main(String args[]) { int count, xPos=25; for ( count=1; count<=10; count++ ) { if ( count==5 ) break; System.out.println(count ); xPos += 10; } } }
A.1 2 3 4
B.1 3 4
C.编译错误
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题:
有如下程序: #include <iostream> using namespace std; class MyClass { public: MyClass() { ++count; } ~MyClass() { --count; } static int getCount() { return count; } private: static int count; }; int MyClass::count=0; int main() { MyClass obj; cout<<obj.getCount(); MyClass *ptr=new MyClass; cout<<MyClass::getCount(); delete ptr; cout<<MyClass::getCount(); return 0; }程序的输出结果是
A.121
B.232
C.221
D.122
第10题:
下面程序的运行结果是【 】。
include <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 = O;
int main()
{
cout<<count:: test()<<" ";
count c1, c2;
cout<<count:: test()<<endl;
return 0;
}