Select the correct rules for encapsulation. If any rules need to be imposed in a particular order, then say so, mentioning which rules.
a. Make all class member variables public members of the class.
b. Place the interface in the header file. What is the interface?
c. Place the implementation in a separate code file (with file extension required by your compiler: .cpp, .cxx, etc), called the implementation file. What is the implementation?
d. Having private members visible in the interface violates the philosophy of separating the interface from the implementation. Separate interface and implementation requires removal of all the private members from the class definition. You must put these in another part of the class definition in the implementation.
Except for a) and d), all of the above, in no particular sequence, so long as all are done. All variable members should be private, not public. The suggestion in d) to divide the class definition across the implementation and interface files is not possible.
Explanation: a) Having public data members violates encapsulation. The private members are part of the implementation, not part of the interface. Since a class in C++ cannot be split across two files and other C++ design reasons, the compromise of putting private members in the class definition was reached.
b) What is the interface? The interface is the class definition containing constructors, destructor, declarations of each basic operation of the class, declarations of friend functions. Grouped with the class definition are the declarations of ordinary functions and of nonmember overloaded operators and any needed comments that explain how to use functions.
c) What is the implementation? The implementation consists of the definitions of all member functions, overloaded operator definitions (members and nonmembers) with definitions of any helping functions or other additional items necessary to these definitions. Inclusion of the interface file in the implementation file will be necessary to compile the implementation file.
d) A class in C++ cannot be split across two files. The private members must be placed in the class definition.
You might also like to view...
Which of the following is not true of static local variables?
a. They are accessible outside of the function in which they are defined. b. They retain their values when the function in which they are defined terminates. c. They are initialized to zero if not explicitly initialized by the programmer. d. They can be of type int.
Which of the following statements about adapters is false?
a. An adapter class implements an interface. b. An adapter class provides a default (empty) implementation of every method in the interface. c. Programmers override selected adapter methods. d. A ComponentListener is a ComponentAdaptor.
MPLS inserts a 32-bit header between Layer 2 and Layer 3 headers. Because this header is ________ between the Layer 2 and Layer 3 headers, it is sometimes referred to as a(n) ________ header
A) inserted, insert B) added, addon C) inserted, proxy D) shimmed, shim
A bit is set and the controller continues to run when the controller encounters a(n) ____________________. An example would be the battery light alerting that the battery needs to be changed.
Fill in the blank(s) with the appropriate word(s).