A-A+

若有如下程序: #include<iostream> using namespace std

2022-08-05 20:33:46 问答库 阅读 171 次

问题详情

若有如下程序: #include<iostream> using namespace std; int s=0; class sample { static int n; public: sample(int i) { n=i; } static void add() { S+=n; } }; int sample::n=0; int main() { sample a(2),b(5); sample::add(); cout<<s<<endl; return 0; } 程序运行后的输出结果是()。
A.2
B.5
C.7
D.3请帮忙给出正确答案和分析,谢谢!

参考答案

正确答案:B

考点:程序