问题
单项选择题
根据下面的程序,可以在主程序中使用的合法语句是( )。 #include <iostream> using namespace std; class Person{int age;voidtest(){} public:Person(intage){this->age=age;}void ShowAge(){cout<<"the Person’s age is",<<age;} }; void main(){Person wang(23); }
A.wanage=45
B.wanwang(45)
C.wanShowAge()
D.wantest()
答案
参考答案:C
解析: ShowAse是类的公有成员,可以由对象访问,其他的为私有成员,类对象不能访问。