以下装箱、拆箱语句中,错误的有()
第1题:
使用VC6打开考生文件夹下的工程proj1。此工程包含一个源程序文件mainl.cpp,但该程序运行有问题。请改正主函数中的错误,使程序的输出结果是:
member = 0
member = 5
member = 10
源程序文件 mainl.cpp 清单如下:
//mainl.cpp
include <iostream>
using namespace std;
class MyClass
{
public:
MyClass(int i)
{
member=i;
}
void SetMember(int m)
{
member=m;
}
int GetMember()const
{
return member;
}
void Print() const
{
cout<<"member="<<member<<end1;
}
private:
int member;
};
int main()
{
/***************found***********/
MyClass obj1;
obj1. Print();
MyClass obj2(3);
/***************found***********/
obj1.member = 5;
/***************found***********/
MyClass. SetMember(10);
obj1. Print();
obj2. Print();
return 0;
}
第2题:
有如下程序: #include<iostream> using namespace std; class TestClass{ static int i; public: TestClass(){i++;} ~TestClass(){i--;} static int getVal(){return i;} }; int TestClass::i=0; void f(){TestClass obj2;cout<<obj2.getVal();} int main(){ TestClass obj 1; f(); TestClass *obj3=new TestClass;cout<<obj3->getVal(); delete obj3;cout<<TestClass::getVal(); return 0; } 程序的输出结果是( )。
A.232
B.221
C.222
D.231
第3题:
把一个对象写到一个流中相对比较简单,具体是通过调用ObjectOutputStream类的writeObject()方法实现的,那么该方法的定义为( )。
A.public final int writeObject(Object obj) throws IOException
B.public final void writeObject(Object obj) throws IOException
C.public Object writeObject(Object obj) throws IOException
D.public final Object writeObject(Object obj) throws IOException
第4题:
阅读以下程序: #include<iostream.h> class kk { int m; public: static int n; kk() { m=0; 1 void setvalue() { m++; n++; } void output() { cout<<"m="<<m<<",n="<<n<<endl; } }; int kk::n; void main() { kk obj1,obj2; obi1.Setvalue(); obj1.output(); obj2.setValue(); Obj2.output(); } 该程序的执行结果是( )。
A.m=1,n=1
B.m=l,n=l m=1,n=1 m=1,n=2
C.m=1,n=1
D.m=1,n=1 m=2,n=1 m=2,n=2
第5题:
有如下程序 public class Test { int a,b; Test ( ) { a = 100; b = 200; } Test(int x, int y) { a = x; b = y; } public static void main(String args[]) { Test Obj1 = new Test(12,45); System.out.println("a = "Obj1.a+" b = "+ObB) ; Test Obj1 = new Test(); System.out.println("a = "Obj1.a+" b = "+Obj1.B) ; } } 程序的运行结果为( )。
A.a=100 b=200 a=12 b=45
B.a=12 b=45 a=100 b=200
C.a=12 b=200 a=100 b=45
D.a=100 b=45 a=12 b=200
第6题:
include<iostream>
include<string>
using namespace std;
class MyClass
{
public:
MyClass(int i=0){member=i;}
void SetMember(const string m){member="big"+m;m=member;}
string GetMember(){return member;}
void print()const{cout<<"Stu:"<<member<<endl;}
private:
string member;
};
void main()
{
MyClass obj1,*obj2;
string i="wang lin";
obj2=&obj1;
obj2->SetMember(i);
obj1.print();
}
第7题:
若有以下程序:#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
第8题:
以下程序的执行结果为( )。 #include<iostream.h> class myClass { Dublic: myClass(int data) ; myClass(){value=0; }; myClass(myClass &obj); void print(){ cout<<value<<end1; } ~myClass(){} private: int value; }; myClass::myClass(int data) {value=data; } myClass::myClass(myClass &Obj) { value=obj.value; } void main() { myClass a(100); myClass b(a) ; b.print(); }
A.0
B.100
C.10
D.程序编译时出错
第9题:
11. public static void main(String[] args) { 12. Object obj =new int[] { 1,2,3 }; 13. int[] someArray = (int[])obj; 14. for (int i: someArray) System.out.print(i +“ “) 15. } What is the result? ()
第10题:
11.public static void main(String[]args){ 12.Object obj=new int[]{1,2,3}; 13.int[] someArray=(int[])obj; 14.for(inti:someArray)System.out.print(i+"") 15.} What is the result?()
第11题:
length()
size()
get(int index)
add(Object obj)
第12题:
123
Compilation fails because of an error in line 12.
Compilation fails because of an error in line 13.
Compilation fails because of an error in line 14.
A ClassCastException is thrown at runtime.
第13题:
A.123
B.Compilation fails because of an error in line 12.
C.Compilation fails because of an error in line 13.
D.Compilation fails because of an error in line 14.
E.A ClassCastException is thrown at runtime.
第14题:
有如下程序:#include <iostream>using namespace std;class Obj { static int i;public: Obj(){i++;} -Obj(){i--;} static int getVal(){return i;} };int Obj::i=0;void f(){Obj ob2; cout<<ob2.getVal(); }hat main(){ Obj ob1; f(); Obj *ob3=new Obj; cout<<ob3->getVal(); delete ob3; cout<<Obj:: getVal(); return (); }程序的输出结果是( )。
A.232
B.231
C.222
D.221
第15题:
若有以下程序:#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
第16题:
有如下程序: #include<iostream> using namespace std; class Obj{ static int i; public: Obj{i++;} 一Obj{i一一;} static int getVal{return i;} }; int Obj::i=0: void f{Obj ob2;cout<<ob2.getVal;} int main{ Obj obl; f; Obj}ob3=new Obj;cout<<ob3一>getVal; delete ob3;cout<<Obj::getVal; return 0; } 执行这个程序的输出结果是( )。
A.232
B.231
C.222
D.221
第17题:
若有以下程序: #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
第18题:
下面程序段的输出结果为 public class Test { int a, b; Test() { a=100; b=200; } Test(int x,int y) { a=x; b=y; } public static void main(String args[]) { Test Obj1=new Test(12,45); System.out.println("a=+Obj1.a+" b="+Obj1.B) ; Test Obj2=new Test(); System.out.println("="+Obja+" b="+ObjB) ; } }
A.a=100 b=200 a=12 b=45
B.a=12 b=45 a=100 b=200
C.a=12 b=200 a=100 b=45
D.a=100 b=45 a=12 b=200
第19题:
有以下程序 #include<iostream> using namespace std; class MyClass { public: MyClass(int n){number =n; } //拷贝构造函数 MyClass(MyClass& other) {number=other.number;} ~MyClass() {} private: int number; }; MyClass fun(MyClass p) { MyClass temp(p); return temp; } int main() { MyClass Obj1(10),obj2(0); MyClass obj3(obj1); obj2=fun(obj3); return 0; } 程序执行时,MyClass类的拷贝构造函数被调用的次数是
A.5
B.4
C.3
D.2
第20题:
下列程序编译错误,是由于划线处缺少某个语句,该语句是______。
include<iostream.h>
class A
{
private:
int numl;
public:
A( ):numl(0){}
A(int i):numl(i){}
};
class B
{
private:
int num2;
public:
B( ):num2(0){}
B(int i):num2(i){}
int my_math(A obj1, B obj2);
};
int B::my_math(A obj1,B obj2)
{
return(obj1.numl+obj2.num2);
}
void main(void)
{
A objl(4);
B obj,obj2(5);
cout<<"obj1+obj2:"<<obj.my_math(obj1,obj2);
}
第21题:
获取单列集合中元素的个数可以使用以下哪个方法?()
第22题:
object obj=100; int m=(int)obj;
object obj=100; int m=obj;
object obj=(int)100; int m=(int)obj;
object obj=(object)100; int m=(int)obj;
第23题:
Compilation fails because of an error in line 13.
A ClassCastException is thrown at runtime.
1 2 3
Compilation fails because of an error in line 14.
Compilation fails because of an error in line 12.