输出171.0
输出171
第2行和第5行编译报错
第10行编译报错
第1题:
有如下程序: #include<iostream.h> Using namespace std; Class Demo { public: Demo(){ cout<<“default constructor\n”;} Demo(const Demo &x){ cont<<“copy constructor\n”;} }; Demo usercode(Demob){Demo c(b);return c;} int main() {
A.1和1
B.1和2
C.2和3
D.2和4
第2题:
下列程序的功能是为变量赋值,程序运行后,输出i=51。请改动main方法中的错误,使程序能够正确编译、运行并输出正确的结果。
注意:不改动程序结构。
class A
{
private int a;
public void setA (int x)
{
a=x;
}
public int getA()
{
return a;
}
}
public class MethodTest
{
public static void main(String args[])
{
A a=A();
a.getA(51);
int i=a.getA();
System.out.println ("i="+i);
}
}
第3题:
A.输出171.0
B.输出171
C.第2行和第5行编译报错
D.第10行编译报错
第4题:
有如下程序: #include<iostream.h> using namespace std; class Demo { public: Demo(){ cout<<"default constructor\n";} Demo(const Demo &X){ cont<<"copy constructor\n";} }; Demo userCode (Demo b){Demo c(b);return c;} int main() { Demo a,d; cout<<"calling userCode()\n"; d=userCode(a); return 0; } 执行上面程序的过程中,构造函数Demo()和Demo(const Demo &x)被调用的次数分别是( )。
A.1和1
B.1和2
C.2和3
D.2和4
第5题:
有以下程序:
include <iostream>
include <string>
using nameSpace std;
class person
{
int age;
Char * name;
public:
person ( int i, Char * str )
{
int j;
j = strlen( str ) + 1;
name = new char[ j ];
strcpy( name, str );
age = i;
}
~person()
{
delete name;
cout<<"D";
}
void display()
{
cout<<name<<":"<<age;
}
};
int main()
{
person demo( 30,"Smith" );
demo.display();
return 0;
}
则该程序的输出结果为:【 】。
第6题:
执行下面的程序段,输出结果为______。
public class Q
{
public static void main(String argvr))
{
int anar[]=new int[5];
System.out.println(anar[0]);
}
}
第7题:
下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te
A.0
B.1
C.2
D.3
第8题:
有如下程序: #include<iostream> using namespace std; class Demo { public: Demo(){ cout<<"default constructor\n";} Demo(const Demo & x){ cout<<"copy constructor\n":} }; Demo userCode(Demo b){DemoC(b);return c;} int main() { Demo a,d; cout<<"calling userCode()\n"; d=userCode(a); return 0; } 执行上面程序的过程中,构造函数Demo()和Demo(const Demo &x)被调用的次数分别是
A.1和1
B.1和2
C.2和3
D.2和4
第9题:
有如下程序: #include<iostream> using namespaee std; class Demo{ public: Demo( ){cout<<"default constructor\n";} Demo(const Demo &x){cout<<"copy constructor\n";} }; Derno userCore(DemoB) {Demo c(B) ;return c;} int main( ){ Demo a,d; cout<<"calling userCode( )\n"; d=userCode(A) ; return 0; } 执行上面程序的过程中,构造函数Demo( )和Demo(const Demo &x)被调用的次数分别为
A.1和1
B.1和2
C.2和3
D.2和4
第10题:
有如下程序: #include <iostream> using namespace std; class Demo public: { Demo () { cout << "default constructor\n"; } Demo (const Demo &x){ cout << "copy constructor\"; } }; Demo userCode(Demo b){ Demo c(b);return c; } int main() { Demo a,d; cout<<"calling userCode()\n"; d=aserCode(a); return 0; }执行上面程序的过程中,构造函数Demo()和Demo(const Demo &x)被调用的次数分别是 ______ 。
A.1和1
B.1和2
C.2和3
D.2和4