Page 121 - DCAP404 _Object Oriented Programming
P. 121
Object-oriented Programming
Notes 5.7 Review Questions
1. Why did C++ add the class keyword?
2. The const keyword specifies that the values of the variable will not change throughout the
program. Analyze.
3. “The static keyword can be used to declare variables, functions, class data members and
class functions”. Justify with an example.
4. Does friend function violate encapsulation? Explain with an example.
5. What are the some advantagesd or isadvantages of using friend functions?
6. What does it mean that “friendship isn’t inherited, transitive, or reciprocal”?
7. “Should my class declare a member function or a friend function?” Do you agree with this
statement? Why or why not. Justify you answers with an example.
8. “A friend function is a function that can access the private members of a class as though it
were a member of that class”. Explain.
9. Write a program which is using the friend function in the nested classes and local classes.
10. Discuss why a friend function is used for accessing the non-public members of a class.
Answers: Self Assessment
1. static data member 2. storage class
3. objects 4. class object
5. this 6. deallocated
7. union 8. constructed
9. class member data 10. function
11. access 12. anywhere
13. friend 14. same time
15. friend
5.8 Further Readings
Online links http://en.wikipedia.org/wiki/Friend_function
http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/topic/
com.ibm.xlcpp8a.doc/language/ref/cplr038.htm
114 LOVELY PROFESSIONAL UNIVERSITY