下列程序的运行结果是
public class test{
private String[] data={“10”,“10.5”};
public void fun(){
double s=0;
for(int i=0;i<3;i++){
try{
s=s+Integer .parseInt(data[i]);
}catch(Exception e){
System.out.print(“errorl:”+data[i]);
}
}
}
public static void main(String[]args){
try{
testd=new test();
d .fun();
}catch(Exception e){
System.out.printIn(“error2”);
}
}
}
A.errorl:10.5
B.error2
C.errorl:10.5 error2
D.以上都不对
第1题:
以下程序的输出结果是_____。
include<iostream.h>
class object
{ private:
int val;
public:
object( ) ;
object(int i) ;
~object( ) ;};
object: :object( )
{ val=0;
cout < < "Default constructor for object" < < endl;}
object: :object(int i)
{ val=i;
cout < < "Constructor for object" < < val < < endl;}
object: :~object( )
{ cout < < "Destructor for object" < < val < < endl;}
class container{ private:
object one;
object two;
int data;
public:
container( ) ;
container(int i,int j,int k) ;
~container( ) ;};
container: :container( )
{ data=0;
cout < < "Default constructor for container" < < endl;}
container: :container(int i,int j,int k) :two(i) ,one(j)
{ data=k;
cout < < "Constructor for container" < < endl;}
container: :~container( )
{ cout < < "Destructor for container" < < endl;}
void main( )
{ container anObj(5,6,10) ;}
第2题:
如下程序的输出结果是 #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
第3题:
下面程序的结果是 #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
第4题:
下列程序的运行结果是 #include<iostream.h> class Location{ private: int X.Y; public: void init(int=0,int=0); void valueX(int val){X=val;} int valueX( ){ return X;} void valueY
A.5 0 6 4
B.0 0 6 4
C.5 0 6 2
D.0 0 6 2
第5题:
若有以下程序:#include <iostream>using namespace std;class A{private: int x;public: int z; void setx(int i) { x=i; } int getx() { return x; }};class B: public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a); z=b; m=c; } void display() { cout<<getx()<<","<<z<<","<<m<<end1; }};int main(){ B obj; obj.setvalue(2,3,4); obj.display(); return 0;程序运行以后的输出结果是( )
A.产生语法错误
B.2,3,4
C.2,2,2
D.4,3,2
第6题:
下列程序的输出结果是______。 #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