Object oriented programming
• Object oriented programming is an approach that provides a way of modularizing programs by creating partitioned memory area for both data and function that can be used as templates for creating copies of such modules on demand .
• In object oriented programming the program is designed around the data being operated upon rather than upon the operation themselves.
• OOP allows to decompose a problem into a number of entities called object and then build data and function around these entity.
• When program is executed the object interact by sending message to one another
• Each object contains data and code to manipulate the data .
Features of OOP :
• Program are divided into number of object.
• Data is hidden and cannot be accessed by external function
• Object may communicate with each other through function
• New data and function can be easily added wherever required.
Object :
• Object are the basic runtime entity in object oriented system .
• For e.g they may represent a person , a place , a bank.
• Programming problem is analyzed in term of object and the nature of communication between them .
• Program object should be chosen such that they match closely with the real world object .
Class :
• Class is way to bind a data and is associated functions together.
• The entire set of data and code of an object can be made an user define datatype with the help of class
• Infact an object is nothing but a variable whose datatype is class
• Once a class has been define user define any number of object belonging to that class
• Class is a collection of object of similar type.
What are friendly function? Give the characteristics of a friendly function .
C++ allows the common function to be made friendly with more than one classes , thereby allowing the function to have access to the private data of class . Such a function need not be a member of any classes.
Non-member function cannot have access to the private data of a class . However , there could be a situation where user would like two classes to share a particular function. At this situation friend function is used.
The keyboard “ friend ” declare the function to be friendly with that class. This function is defined as a normal c++ function . The function definition does not use class – name , keyboard friend or scope resolution operator.
A friend function has following characteristics :
(1) It is not in the scope of the class to which it has been declared as friend .
(2) since it is not in scope of the class, it cannot be called by using object of that class . It is called like a normal c++ function .
(3) It can be declared either in public or the private part of a class without affecting is meaning .
(4) Usually , it has the objects as arguments.
(5) It cannot access the member function directly and has to use an object name and dot operator with each member name .
Comments
Post a Comment