Short Term Questions & Answer:
1. An object is an instance of a _____________.
2. The process of combining data and functions in a single unit is called as__________.
3. ____________ is the ability for a message or data to be processed in more than one form.
4. Class is a _________________ data types.
Ans: User defined
5. Binding can be performed either at ___________ or ______________.
Ans: Compile time, run time.
Long term Questions & Answer:
Ques 1: What is the difference between Procedural Oriented Programming(POP) & Object Oriented Programming(OOP)?
|Comparison Characteristics||Procedural Oriented Programming(POPs)||Object Oriented Programming(OOPs)|
|Program Structure (or) Division
||In POP, program is divided into small parts called functions.||In OOP, program is divided into parts called objects.|
||In POP, Importance is not given to data but to functions as well as sequence of actions to be done.||In OOP, Importance is given to the data rather than procedures or functions because it works as a real world.|
||It follows Top Down approach.||It follows Bottom Up approach.|
||POP does not have any access specifier.||OOP has access specifiers named public, private, protected, etc.|
|Data Moving||In POP, Data can move freely from function to function in the system.||In OOP, objects can move and communicate with each other through member functions.|
|Expansion||In POP, to add new data and function is not so easy.||OOP provides an easy way to add new data and function.|
|Data Access||In POP, most function uses Global data for sharing that can be accessed freely from function to function in the system.||In OOP, data can not move easily from function to function,it can be kept public or private so we can control the access of data.|
|Data Hiding||POP does not have any proper way for hiding data so it is less secure.||OOP provides Data Hiding so provides more security.|
|Inheritance||Their is no provision of inheritance.||Inheritance achieved in three modes public private and protected.|
|Data sharing||Global data is shared among the functions in the program.||Data is shared among the objects through the member functions.|
|Friend functions/classes||No concept of friend function.||Classes or function can become a friend of another class with the keyword “friend”.
“friend” keyword is used only in c++
||In POP, Overloading is not possible.||In OOP, overloading is possible in the form of Function Overloading and Operator Overloading.|
|Examples||Example of POP are : C, VB, FORTRAN, Pascal.||Example of OOP are : C++, JAVA, VB.NET, C#.NET.|
Ques 2: What is Object Oriented Programming(OOP) and also explain the features of OOPs?
Object-Oriented Programming (OOP) is the term used to describe a programming approach based on objects and classes. The object-oriented paradigm allows us to organise software as a collection of objects that consist of both data and behaviour. This is in contrast to conventional functional programming practice that only loosely connects data and behaviour.
FEATURES OF OOP:
- Dynamic Binding
- Message Passing
Object: Object is a collection of number of entities. Objects takes space in the memory. Objects are instances of classes. When a program is executed , the objects communicate by sending messages to one another. Objects can interact without having know details of each others data or code.
Class: Class is a collection of objects of similar type. Objects are variables of the type class. Once a class has been defined, we can create as many objects belonging to that class. Also, class are user-defined data types.
days sunday, monday, tuesday ;
In the above statement sunday, monday, tuesday are the object which belong to the class days.
In other words, classes acts as data types for objects
Encapsulation: One of the most fundamental concepts of object oriented programming is encapsulation. Combining data and functions into a single unit called class and the process is known as Encapsulation. Data encapsulation is important feature of a class. Class contains both data and functions. Data is not accessible from the outside world and only those function which are present in the class can access the data.
Inheritance: Inheritance is the capability of a new class to inherit the data and functions of the old class without knowing the details of old class. The new class is known as derived class and the old class is known as base class. The derived class not only inherits some characteristics from its base class but also adds some new features of its own. The set of base class and derived class instances is referred as the class inheritance hierarchy.
Example: A typical example of inheritance:
In this example, Vehicle is the base class and Two wheeler, Three wheeler and Four wheeler are the derived classes.
Reusability: The concept of inheritance provides an important extension to the idea of reusability. Reusability is nothing but re- usage of structure without changing the existing one but adding new features or characteristics to it. It is very much needed for any programmers in different situations.
The main advantages of reusability that it helps in reducing the code size since classes can be just derived from existing one and one need to add only the new features and it helps users to save their time.
Polymorphism: Polymorphism means that ability to take more than one form. So Polymorphism as the name suggests is a certain item appearing in different forms or ways. Polymorphism allows a user to create multiple definitions for operators and functions at run-time depending on the context a particular definition is used. In other words, polymorphism is the ability for a data to be processed in more than one form or you can say that different objects react in different manner to the same operation.
Polymorphism can be achieved by using two ways:
- Operator Overloading
- Function Overloading
Dynamic Binding: Binding is performed either at compile time or at run time. The binding which is done at compile time is known as static binding(early binding) and the binding which is done at run time is known as dynamic binding(late binding). Dynamic binding refers to linking of function call with function definition is called binding and when it is take place at run time called dynamic binding.
Message Passing: The process by which one object can interact with other object is called message passing.
In other words, we can say that message passing is the idea of sending message to an object, causing it to perform an operation by invoking the appropriate function of the object.