Question

Question 1 (20 marks) (a) Explain at least TWO (2) major aspects of an object-oriented programming...

Question 1 (20 marks)

(a) Explain at least TWO (2) major aspects of an object-oriented programming (OOP).

Provide suitable examples, where necessary. [10 marks]

(b) Describe TWO (2) advantages of OOP. [10 marks]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a) The two major aspects which we will discuss are Abstraction and encapsulation.

ABSTRACTION :

We define abstraction as hiding all the unnecessary details from the user. To understand it with a real time example, let's consider a TV remote, we just press the buttons to switch amongst the channels, increase or decrease the volume, turn it on or off but have we ever thought of how it works ? The dails of how the buttons work are hidden from the outside world. Similarly, we can hide all the unnecessary details of our code from th outside world, this is what is called Abstraction. We can achieve abstraction through access modifiers which are printae, public and protected. Private functions or data members cannot be accessed outside the class and hence are hidden from the outside world.

ENCAPSULATION :

Encapsulation is defined as keeping all the data members and the functions at one place together, i.e. encapsulate them. This is achieved through a class in C++, wherein we define the members and the function for that class. This provides more readability to the code and the code looks much cleaner, making it simple to understand. For example let us take a car class.

class car
{
public :
int num_gears;
  int max_speed;
int model;
};

Here we have included the model, num_gears and max_speed under one class and can be used for any car object.

b) Advantages of OOP :

In real life we deal with lot of objects such as people, car, account, etc. Hence, we need our software to be analogous to real-world objects. Real world objects have data-type properties such as name, age for people, model name for car and balance for account, etc. Moreover, real-world objects can also do certain things such as people talk, cars move, account accumulates, etc. We want our code to mimic the way these objects behave and interact. Hence, Object Oriented Programming allows the program to be closer to real world and thus making it less complex.

Also it makes the software reuse feasible and possible, for example, we don't want to define a student every time we use it, hence using OOP, we just create the blueprint for the student object and use it whenever required.

Add a comment
Know the answer?
Add Answer to:
Question 1 (20 marks) (a) Explain at least TWO (2) major aspects of an object-oriented programming...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT