2043 ooptest
1
How does private visibility affect attributes and operations?
-
A、
Makes them accessible only to other classes in the same package
-
B、
Makes them accessible only to the class itself and its friends
-
C、
Makes them accessible to all clients
-
D、
Makes them accessible only to the class itself
-
E、
Makes them accessible only to subcalsses
B
填空题
1
C++ programmers concentrate on creating their own user-defined types called class .
2
If required, member functions can be declared constant member functions as to prevent even an inadvertent change in the data members.
3
A variable that is part of a class, yet is not part of an object of that class, is called a static member.
4
Only one copy of a static data member exists for the entire class.
5
#include
using namespace std;
(1)Class OOPClass{
(2) public
void displayMessage() {
cout << “Welcome to the OOP World!\n”;
}
};
int main() {
(3) OOPClass myOOPClass ; // creating an object named myOOPClass
(4)myOOPClass.displayMessage() ;
return 0;
}
The output is: Welcome to the OOP World!
判断题
- The return type of a constructor in C++ is void. F
在C++中构造函数返回的类型可以是空的,也可以是其他类型
2.Member function cannot be overloaded. F
成员函数可以被重载
3.Structures in C++ can have member functions also. T
**C++中的结构体和C不一样。 默认情况下,结构的基数默认是公共继承(public)的,而默认情况下,类的基数则是私有(private)的继承。 结构无法封装因为成员函数只能是public,而类可以封装。 默认情况下,用关键字class定义的类的成员是私有的。默认情况下,用关键字struct或union定义的类的成员是公共的。 **
4.Structure members are private by default. F
如上题解答,故4题错
5.Only constant member function can be called for constant object. T*
常量对象只能调用常量函数,不能调用非常量函数,但是非常量对象,两者均可调用