关于以下程序代码的说明正确的是 ( )(1)class HasStatic{(2)private static int x=100;(3)public static void main(String args[]){(4)HasStatic hs1=new HasStatic();(5)hs1.x++;(6)HasStatic hs2=new HasStatic();(7)hs2.x++;(8)hs1=new HasStatic();(9)hs1.x++;(10)System.out.println("x="+x);(11)}(12)}
A.(5)行不能通过编译,因为引用了私有静态变量
B.(10)行不能通过编译,因为x是私有静态变量
C.程序通过编译,输出结果为:x=103
D.程序通过编译,输出结果为:x=100
第1题:
若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb (int x) { b=x; } void showb() { cout<<b<<","; } }; class C :public A,private B { private: int c; public: void setc(int x, inc y, int z) { c=z; seta (x); setb (y); } void showc() { showa (); showb (); cout<<c<<end1; } }; int main () { C c; c. setc(1,2,3); c.showc(); return 0; } 程序执行后的输出结果是
A.1,2,3
B.1,1,1
C.2,2,2
D.3,3,3
第2题:
若有以下程序:#include <iostream>using namespace std;class A{private: int a;public: void seta(int x) { a=x; } void showa() { cout<<a<<","; }};class B{private: int b;public: void setb(int x) { b=x; } void showb() { cout<<b<<","; }};class C: public A, private B{private: int c;public: void setc(int x, int y, int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; }};int main(){ C c; c.setc(1,2,3); c.showc(); return 0;}程序执行后的输出结果是( )。
A.1,2,3
B.1,1,1
C.2,2,2
D.3,3,3
第3题:
第4题:
有以下程序 #include<iostream> using namespace std; class sample { private: int x; public: sample(int a) { x=a; } friend double square(sample s); }; double square(sample S) { return s.x*s.x; } int main() { sample s1(20),s2(30); cout<<square(s2)<<endl; return 0; } 执行结果是
A.20
B.30
C.900
D.400
第5题:
若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa,( ) { cout<<a<<", "; } }; class B { private: int b; public: void setb(int x) { b=x; } void showb () { cout<<b<<", "; } }; class C : public A, private B { private: int c; public: void setc(int x,int y, int z) { c=z; sera (x); seth (y); } void showc() { showa(); showb(); cout<<c<<end1; } }; int main () { C c; c.setc(1,2,3); c.showc(); return 0; } 程序执行后的输出结果是( )。
A.1,2,3
B.1,1,1
C.2,2,2
D.3,3,3
第6题: