Class and Objects
Exercises
Fill in The Blanks
1. A class provides __security____
2. Class __access___ specifies the types and scope of its
members.
3. Data hiding is implemented through the _private___visibility
label.
4. A function defined inside the class is treated as an
member____function
5. Variables of a class are called __object____
6. member functions can be accessed with _object___ and
_pointer_____
7. An object is an ____instance___of a class.
8. Memory for member functions is allocated when __object
created___
9. static data members are automatically initialized to _0___
10. in technique a copy of the actual objects is created and passed
to the called functions. Call by value
11. Local classes can use any global variable but with _scope
resolution___
12. whiledeclaring an object of inner class, name of the inner
class must be proceded with name of the outer class___
13. ___friend_ function and _friend__ classes breaks the rules of
the data hiding in C++.
14. Keyword friend is used in function _declaration___ but not
in function_defination___
15. friendship are__explicit____
16. ___bit field__ allows users to reserve the exact amount of
bits required for storage of values.
17. _size
of_____ operator cannot be applied to bit -field
components.
18. The default integer type for a bit field is ___unsigned___
19. keyword private and public are called __access__specifiers.
State True or False
1. By default member of structure are private. false
2. Member of the structure can be accessed from the main()
using the dot operator true
3. All members declared public cab be accessed only from
within the class. false
4. We can have a class with all the private members. true
5. We cannot have private member functions false
6. Memory is allocated when we declare the class false
7. All the member functions defined outside the class are inline
false
8. All objects of the class share its member functions true
9. only one copy of the static member is created in memory
true
10. static data members are a part of the objects. false
11. Static and non static member functions in the same
class which same names and same number and types of
the arguments is possible. false
12. This pointe is passed explictly to the member function false
13. this pointer is a part of the object itself. false true
14. local classes can have static data members. true
15. Member functions of a local class can be defined inside or
outside the class. true
16. Friend functions are external functions with special
access privileges true
17. friend function can access this pointer. false
18. friendship is explicitly specified. true
19. You can have arrays of bit fields. false
20. Unnamed bit field can be referenced. false
21. A programmer can change the value of this pointer. false
Multiple Choice Questions
1. In C++, the declaration of functions and variables are
collectively called …….
A) class members
B) function members
C) object members
D) member variables
2. The keywords private and public used in C++ are known as
………….
A) keyword labels
B) visibility labels
C) declaration labels
D) display labels
3. The variables declared inside the class are known as data
members and functions are known as ………….
A) data functions
B) inline functions
C) member functions
D) member variables
4. Only the …………………. can have access to the private
members and private functions.
A) data functions
B) inline functions
C) member functions
D) member variables
5. The binding of data and functions together into a single class-
type variable is referred to as …………..
A) encapsulation
B) data abstraction
C) polymorphism
D) all of the above
6. When the function is defined inside a class, it is treated as
………………….
A) data function
B) inline function
C) member function
D) member variable
7. A member function can be called by using its name inside
another function of the same class, which is known as …………
of member function.
A) sub function
B) sub member
C) nesting
D) sibling
8. A ………………. member function can only be called by
another function that is member of it’s class.
A) friend
B) static
C) public
D) private
9. ……………….. member variable is initialized to zero when the
first object of its class is created where no other initialization is
permitted.
A) friend
B) static
C) public
D) private
10. Static variables are associated with the class itself rather than
with any class object, they are also known as…………….
A) class variables
B) object variables
C) function variables
D) internal variables
11. Static variables are like ………………… as they are declared
in a class declaration and defined in the source file.
A) inline member function
B) non inline member function
C) static member function
D) dynamic member function
12. A …………….. can have access to only other static members
declared in the same class.
A) constant member function
B) private member function
C) static member function
D) friend function
13. A static member function can be called using the
………………… instead of its objects.
A) variable name
B) function name
C) Class name
D) object name
14. While using an object as a function argument, a copy of the
entire object is passed to the function in ………….. method.
A) pass-by-value
B) pass-by-reference
C) pass-by-variable
D) pass-by-function
15. A ……………………., although not a member function, has
full access rights to the private members of the class.
A) constant member function
B) private member function
C) static member function
D) friend function
16. ……………. can be invoked like a normal function without
the help of any object.
A) constant member function
B) private member function
C) static member function
D) friend function
17. A ………….. can only be called by another function that is
member of its class.
A) constant member function
B) private member function
C) static member function
D) friend function
18. If a member function does not alter any data in the class, that
may be declared as ………………..
A) constant member function
B) private member function
C) static member function
D) friend function