+199

Some real life Examples of Object-oriented programming (OOP) concept.

1 .Polymorphism : The process of representing one form in multiple forms is known as Polymorphism. Example - Suppose if you are in class room that time you behave like a student, when you are in market at that time you behave like a customer, when you at your home at that time you behave like a son or daughter, Here one person present in different-different behaviors. 2. Abstraction : Abstraction is the concept of exposing only the required essential characteristics and behavior with respect to a context. Examples - Abstraction shows only important things to the user and hides the internal details, for example, when we ride a bike, we only know about how to ride bikes but can not know about how it work? And also we do not know the internal functionality of a bike. Abstraction is ATM Machine; All are performing operations on the ATM machine like cash withdrawal, money transfer, retrieve mini-statement…etc. but we can't know internal details about ATM. 3. Encapsulation = Data Hiding + Abstraction. Example - Looking at the example of a power steering mechanism of a car. Power steering of a car is a complex system, which internally have lots of components tightly coupled together, they work synchronously to turn the car in the desired direction. It even controls the power delivered by the engine to the steering wheel. But to the external world there is only one interface is available and rest of the complexity is hidden. Moreover, the steering unit in itself is complete and independent. It does not affect the functioning of any other mechanism. 4. Inheritance - Example - Father gives his property to child , father got that properties from child’s grandfather , so child is the taker and father is giver , hence father works as a base class and child as derived class , • you can explain is that the child couldn’t give its property to father so Inheritance is one sided • why it is needed? so you can explain like same properties needed in multiple class you need not to write multiple times

3/10/2017 7:43:37 AM

Rashmi Ranjan Bisoi

83 Answers

New Answer

+13

Inheritance Inheritance is a way to reuse once written code again and again. The class which is inherited is called base calls & the class which inherits is called derived class. So when, a derived class inherits a base class, the derived class can use all the functions which are defined in base class, hence making code reusable.

+37

Thanks for these great explanations! :)

+13

Ok so now I have take time to read :) I feel programming should be teach that way and everyone in the world could develop an OS :D Great post, thanx!

+11

Q)  What is avirtual function? ANS:. Virtual function is a member function ofclass and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration. Virtual function can be achieved in C++, and it can be achieved in C Languageby using function pointers or pointers to function.

+10

Thanks for such explanations!!

+8

12 polymorphism Process of representing one form in many ways. Example Your behavior that is, u behave differently with different person in different place I mean, to parents I'll be good son, and to a friend u r a buddy and u share things with him /her and to teachers u show some respect . Here it behavior is goes on changing with people u meet. 2:abstraction Process of showing essential information to user and hide the rest Example : Think u have a car, and u are riding car now, when u apply break u know that car gone a stop but u don't know what is the process happened when u applied break

+8

Let us begin expressing a 'Human' object in C++, with a 'name' attribute. The following code includes things I haven't introduced yet, but you may be able to understand the fundamental concept of what is going on given the words used. They will be explained afterwards. class Human { private: std::string nameC; public: Human(const std::string & name) : nameC(name) { } }; The first new thing you will notice when reading from top to bottom is the opening brace ({). Braces are the main way to delineate objects and 'scopes' to the compiler. In this case everything between the opening brace and closing brace (the one with the ";" after it) is the definition of the 'Human' class.

+7

The common example for polymorphism often given "your behavior different with different people or at different places" is not really right. It is an example that is demonstrating overloading. Overloading is same interface (name) different input data hence different output. If you take behavior example, you behave differently at school, work and home. What is common here is behave, so it is an interface. When input is school, behave has one output as you (object) behave as certain way at school. When input is work, behave has another output as you behave different at work. When input is home, behave has yet another output. Three cases have three different output because the input is different, but the interface (behave) is same and more importantly there is only one object (you). Technically polymorphism is one interface different behavior due to different objects of similar/related type. Good example of polymorphism in real life, in an exam paper, each student writes a different answer to a same question (assuming question requires descriptive answer). Here there is only one interface, a question in the exam paper. It has different behavior (answers) due to different objects (students) of similar/related type (human).

+6

Great Examples

+6

Thank you and great concepts, and again thanks😉😌

+5

Really great analogy mate, first time I get a bit of insight into OOP

+5

Thanks Rashmi for such a wonderful explanation I need to know how we use this concept in programming. There is interface,abstract class, static class and final class. Many people do not know how to use this concept and why? What are advantages and how this concept make our life happy in programming I hope you understand my doubt regarding prove concept by practically rather than theortical

+5

Great allusions.

+5

thanks @Rashmi...helped a lot!!!

+5

@raqshandra ... En- means "within" or "in" (so encircle..."in a circle"), and "capsule": a type of container Astronauts traveled inside a space capsule. Fish oil, medicine, etc comes in capsules. Capsules completely surround (contain) things by "encapsulating" them. When you want what's inside, you must access the 'encapsulating layer' first.

+5

Thanks dude... The illustrations are perfect!

+5

good. really helpful 👍👌👌👍 thanks.

+4

now , some rich people have self driving cars and the cars are mainly built in google.

+4

Programming is easy to understand like that.. With real life .. and analogy.. up vote!!

+4

I started programming in Perl and then some C. I made heavy use of multi-dimensional arrays to store large amounts of data. Then when I came to Python, PHP and Java I really learned to like the OOP approach to programming, making it more easily to handle data, not having to remember the structure of multidimensional arrays. Now, I just had to think what disadvantages OOP has. What do you think? Let's distinguish two sorts of disadvantages: OO is often provided through such imperfect vehicles as C++ and Java [discuss their defects]; and OO is inapplicable because [explain many mismatches].