W2: CLASSES Flashcards

_ Classes and Scoped Enumerations

1
Q
#W2-Q1: Definition of USER-DEFINED TYPES? 
_ What are they?
A

_ 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
#W2-Q2: What is CLASS types used for?
_ What is ENUMERATION types used for?
A

_ 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

W2-Q3: List some main points about a CLASS

A
_ 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
#W2-Q4: How to define a CLASS type?
_ Characteristics of CLASS, STRUCT, UNION
A
_ 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

W2-Q5: What is a CLASS DEFINITION?

A

A class definition introduces a NEW type into a translation unit, declares the SUB-OBJECTS of the class and its MEMBER FUNCTION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

W2-Q6: Describe some main points about the SUB-OBJECT DECLARATIONS

A
_ 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

W2-Q7: What is a FORWARD class declaration?

A

A forward class declaration introduces a NEW type to a translation unit, WITHOUT declaring its sub-objects or member function types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

W2-Q8: How to initialize NON-STATIC data?

A

_ 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

W2-Q9: Any constructor of a class can initialize a data member directly. True or False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

W2-Q10: A class without a Class-name is called

A
_ 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

W2-Q11: What are class VARIABLES?

A
_ 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

W2-Q12: What are class FUNCTIONS?

A
_ 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

W2-Q13: What is a STRUCT?

A
_ 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

W2-Q14: What is a UNION?

A
_ 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

W2-Q15: What is an ENUMERATION?

A

_ 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

W2-Q16: What is a SCOPED ENUMERATION?

A

_ A SCOPED enumeration RESTRICTS access to a symbolic constant based on its scope.
_ Symbolic constants with the same name but different scopes are distinct values.