1. What is an Object? 2. What is a method? Does it relate to the concept ofOOP(o
ID: 3609582 • Letter: 1
Question
1. What is an Object?
2. What is a method? Does it relate to the concept ofOOP(object-oriented programming)?
3. Name two instances of the MAMMAL class.
4.
a. Discuss the concept of INHERITANCE...
b. What is Polymorphism? How is it applied in real life?
c. In calculating the area of a rectangle, what are somemethods, fields and objects used in this program?
d. What is the difference between an ACCESSOR method and aMUTATOR method?
5. In a coherent paragraph, explain how the following arerelated:-
a. Object
b. Encapsulation
c. Public Methods
d. Private Methods
e. Data Hiding
f. Reusability
Explanation / Answer
1. Object:
An object is a basic-run time entity. They may represent a person,a place, a table of data or any item that the program may handle.They also represent user defined data types such as vectors andlists.
2. Method :
A method is a self contained block of code to solve a particularproblem whenever it is called. It relates to oop, because everyprogram contains set of member functions(methods) and membervariables.
3. The instance of MAMMALclass can be created as,
MAMMAL m1 = new MAMMAL();
MAMMAL m2 = new MAMMAL();
Here, m1,m2 are two instances of MAMMAL class
4.
a. Inheritance is the process by which the objectsof one class acquire the properties of objects of another class. Itsupports the concept of hierarchical classification. We can achievereusability using this.
b. Polymorphism means the ability to take morethan one form. That means an operation an exhibit differentbehavior in different instances.
c. To calculate the area of rectangle, some member variables whichare used are, length, breadth, area and the functions aregetData(), area(). Instances may be defined using the name of theclass
5. a. Object
An object is an allocated region of storage. Since programminglanguages use variables to access objects, the terms object andvariable are often used interchangeably. In object-orientedprogramming, an object may be associated with both the data and theinstructions that operate on that data.
In object-oriented programming (OOP), an instance of a program(i.e. a program running in a computer) is treated as a dynamic setof interacting objects. Objects in OOP extend the more generalnotion of objects described above to include a very specific kindof typing, which among other things allows for:
1.Data members that represent thedata associated with the object.
2.Methods that access the datamembers in predefined ways.
In the case of most objects, the data members can only beaccessed through the methods, making it easy to guarantee that thedata will always remain in a well-defined state
a dot(.) operator is used to call a particular method/functionof an object
b. Encapsulation :
Wrapping up of data and functions into a single unit is calledencapsulation. Data encapsulation is most striking feature of aclass. The data is not accessible to the outside world and onlythose methods which are wrapped in the class can access it.
c. Public Methods:
The methods which are defined under “Public” sectionare called public methods. These methods can be accessed in entireclass and also in the class which is derived from it.
public methods are defined by Classname.prototype.methodName =function(){...} and may be called from outside the object.
d. Private Methods :
The methods which are defined under “Private” sectionare called private methods. These methods can be accessed with thesame function only.
private methods are declared inline inside the object'sconstructor (or alternatively may be defined via varfunctionName=function(){...}) and may only be called by privilegedmethods (including the object's constructor).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.