【单选题】7.6若有下面的程序代码 class Test{ private int m; public static void fun(){ //some code } } 方法fun()如何来访问变量m()
A.将private int m 改成protected int m
B.将private int m 改成public int m
C.将private int m 改成static int m
D.将private int m 改成int m
A.将private int m 改成protected int m
B.将private int m 改成public int m
C.将private int m 改成static int m
D.将private int m 改成int m
A、将privateintm改为protectedintm
B、将privateintm改为publicintm
C、将privateintm改为staticintm
D、将privateintm改为intm
A、protected int m;
B、public int m;
C、static int m;
D、int m;
A、编译通过,输出: 此行将无法被执行!
B、编译通过,输出: 此行将无法被执行! exception: 数组下标不能为负数。
C、编译通过,输出: exception: 数组下标不能为负数。
D、编译不能通过
下列程序运行结果是 。 class test{ long x; static int num; public: test (long m=0) {x=m;} test operator++(); test operator++(int); void Show() { cout<<"the num is:> <<",x="<> < <endl; } }; test test::operator++() { ++x; num is: the answer"> 参考答案: <span style="color:rgb(255, 0, 0)">The num is: 1,x=1 The num is: 2,x=3 The num is: 3,x=3 The num is: 3,x=1</span>
2、下列程序运行结果是 。 #include <iostream.h> class A { long x; public: A(long m) {x=m;} void Show() { cout<<"count="<> <<",x="<> < <endl; } a& operator++(); operator++(int); static int count; }; a::operator++() { ++x; ,x="<<x<<endl; A temp(*this); x++; return temp; } int A::count=1; void main() { A a(1); a.operator++(1); a.operator++(); a.Show(); }<br/><p class=" count="<<count++<<" answer"> 参考答案: <span style="color:rgb(255, 0, 0)">count=1,x=1 count=2,x=3 count=3,x=3</span>
3、下列程序运行结果是 。 class sample{ int x , y ; public : sample( ) { x=y=0 ; } sample( int i , int j) {x=i ; y=j ; } void copy( sample &obj) { *this=obj ; } sample operator--( ) { x-- ; y-- ; return *this; } void print( ){ cout << x << " " << y<< " " ; } } ; void main( ) { sample c1(1 , 2) , c2 ; --c1; c1.print( ) ; c2.copy(c1) ; --c2; c2.print( ) ; }
B.10,12,14
C.8,10,12
D.8,12,10
B.不能编译通过
A、private int num; public string Num { get{return num;} set{num=value;} }
B、private int num; public int Num { get{return num;} set{num=value;} }
C、private int num; public int Num { get{num=value;} set{return num;} }
D、private int num; private int Num { get{return num;} set{num=value;} }
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!