W2: CLASSES Flashcards
_ Classes and Scoped Enumerations
#W2-Q1: Definition of USER-DEFINED TYPES? _ What are they?
_ are types constructed from FUNDAMENTAL, built-in and possibly other user-defined types, using the abstraction mechanisms of the programming language.
_ CLASSES + ENUMERATIONS are user-defined types
#W2-Q2: What is CLASS types used for? _ What is ENUMERATION types used for?
_ encapsulate their own LOGIC, protect their objects’ DATA through access modifiers and manage access to PRIVATE data through PUBLIC member functions
_ represent small sets of values using SYMBOLIC names, making the source code more readable and less ERROR-PRONE
W2-Q3: List some main points about a CLASS
_ A class is a SEQUENCE of types, which need NOT be IDENTICAL. _ Data type and function type constitute the MEMBERS of the class. _ A class does NOT necessarily store its data members CONTIGUOUSLY in a region of memory.
#W2-Q4: How to define a CLASS type? _ Characteristics of CLASS, STRUCT, UNION
_ by using one of the class-keys: class, struct, union _ Classes are STRONGLY encapsulated. The members of a class are PRIVATE BY DEFAULT, which facilitates the HIDING of their INFO _ Structures and unions are WEAKLY encapsulated. The members of a struct or union are PUBLIC BY DEFAULT, which facilitates the SHARING of their INFO
W2-Q5: What is a CLASS DEFINITION?
A class definition introduces a NEW type into a translation unit, declares the SUB-OBJECTS of the class and its MEMBER FUNCTION
W2-Q6: Describe some main points about the SUB-OBJECT DECLARATIONS
_ The sub-object declarations may refer to MOST types including types that POINT to instances of the class itself _ A sub-object declaration may NOT be of the SAME type as the class itself.
W2-Q7: What is a FORWARD class declaration?
A forward class declaration introduces a NEW type to a translation unit, WITHOUT declaring its sub-objects or member function types
W2-Q8: How to initialize NON-STATIC data?
_ through the constructor
_ through the member declaration
_ We initialize DATA MEMBERS that we cannot initialize in the constructor’s body, such as UNMODIFIABLE instance variables
W2-Q9: Any constructor of a class can initialize a data member directly. True or False?
True
W2-Q10: A class without a Class-name is called
_ an ANONYMOUS class _ the definition of an anonymous type is either the definition of an INSTANCE of that type or the declaration of a SYNONYM type.
W2-Q11: What are class VARIABLES?
_ MEMBERS that hold the same INFO for all INSTANCES of the class _ A class variable lasts the LIFETIME of the class definition and holds a value that all instances of the class can share _ The keyword static declares a class variable _ Define and initialize the class variable in the IMPLEMENTATION file _ can refer to a class variable through its class NAME or anyone of its objects' names. _ can access a class variable even if there are NO INSTANCES of the class.
W2-Q12: What are class FUNCTIONS?
_ MEMBERS that access INFO regardless of the number of EXISTING instances of the class _ A class function provides access to PRIVATE class variables. _ To identify a class FUNCTION, preface its declaration in the class definition w/t the keyword static. _ All data members of class scope to which a class function refers must be class VARIABLES. _ A class function may NOT refer to any instance variable.
W2-Q13: What is a STRUCT?
_ A struct is a class that is PUBLIC by default. _ Its members, lmay be of different types and are arranged sequentially but not necessarily contiguously in memory.
W2-Q14: What is a UNION?
_ A union is a collection of types that is PUBLIC by default _ The members of a union may be of different types and are arranged in PARALLEL in memory. _ Unlike a class or a struct, a union assigns the SAME address to all of its data members. _ An object of union type can only hold the value of one of its members at any particular time. _ only the value of the member that was most recently assigned is stored in memory.
W2-Q15: What is an ENUMERATION?
_ An ENUMERATION is a type that holds a small set of symbolic constants, which simplifies the readability of an application.
_ Each enumeration definition declares a type that is different from all other types.
_ Each enumeration has an UNDERLYING type, which defaults to int, if unspecified.