Q.9: Distinguish between the following terms:
a. Object and classes
b. Data abstraction and data encapsulation
c. Inheritance and polymorphism
d. Dynamic binding and message passing
Ans: (a) Object: Objects are the basic runtime entities in an object oriented programming. An object is an instance of a class. It can be uniquely identified by its name and it defines a state which is represented by the values of its attributes at a particular time.
The state of the object changes according to the methods which are applied to it. We refer to these possible sequences of state changes as the behavior of the object.
Class: A class is the implementation of an abstract data type (ADT). It defines attributes and methods which implement the data structure and operations of the ADT, respectively. Instances of classes are called objects. Consequently classes define properties and behaviors of sets of object. Thus a class is a collection of objects of similar type and objects are variables of the type class.
(b) Data abstraction: Abstraction refers to the act representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes.
Data encapsulation: The wrapping up of data and functions into a single unit is known as encapsulation. The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. These functions provide the interface between the objects data and the program. This insulation of the data from direct access by the program is called data hiding or information hiding. As a result data become secured. Thus the encapsulation reduces complexity.
(c) Inheritance: Inheritance is the process by which objects of one class acquire the properties of objects of another class.
Inheritance is the mechanism which allows a class A to inherit properties of a class B. We say ``A inherits from B''. Objects of class A thus have access to attributes and methods of class B without the need to redefine them.
The concept of inheritance provides the idea of reusability. This means that we can add additional features to an existence class without modifying it.
Polymorphism: Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behaviors depend upon the types and number of data used in the operation. The process of making an operator exhibit different behaviors in different instances is known as operator overloading.
(d) Dynamic binding: Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding / late binding means that the code associated with a given procedure call is not known until the time of the call of the run time. It is associated with polymorphism and inheritance.
Message passing: A message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired result. Message passing involves specifying the name of the object, the name of the function and the information to be sent.
Example:
Q.10: What kinds of things can become objects in OOP?
Ans: Object: Objects are the basic runtime entities in an object oriented programming. An object is an instance of a class. It can be uniquely identified by its name and it defines a state which is represented by the values of its attributes at a particular time.
The state of the object changes according to the methods which are applied to it. We refer to these possible sequences of state changes as the behavior of the object.

No comments:
Post a Comment