To understand OOP (Object Oriented Programming), it's likely best to understand what an Object is when referring to programming.
Consider the following:
You are a car mechanic.
A car is delivered to you, and it requires a tune up.
You find that several nuts and bolts are lose on examination.
You search for and acquire an adjustable wrench.
Using the adjustable wrench, you tighten the nuts and bolts.
The result of using the adjustable wrench returns a task completed.
Since there are no other tasks associated with this tune up, the tuneup is completed.
A second car comes in.
The car requires a replacement radiator.
On examination of the radiator, you determine that an array of tools are required, including an adjustable wrench.
You search for and acquire an adjustable wrench.
You use the adjustable wrench to loosen bolts.
You use other tools to further allow the removal and replacement of the radiator.
A new radiator is installed.
You use a combination of tools to again mount the radiator.
You again use the adjustable wrench to tighten the bolts.
The result of using the adjustable wrench returns a completed task (as with the other tools).
Since there are no other tasks associated with this radiator replacement, the replacement is completed.
An object seen in the two examples above would be the adjustable wrench.
In programming, a object is essentially a class that gets instantiated, meets a criteria, and can be reused. For proper object creation, it must meet these four requirements:
It must support polymorphism.
It must support overloading.
It should support overriding (for consistency).
It should support encapsulation (for security).
Much like the adjustable wrench in the above example, the adjustable wrench was performed on both a tune up and a radiator replacement. It essentially was used to remove and tighten bolts and nuts in two different scenarios. The nuts and bolts between the two cars were different, but were classified as the same type of property of which an adjustable wrench be used with. Likewise, two different sets of code may require the use of a class for different reasons, but pass a similar type of peropty and require a similar return value. This is essentially polymorphism, because the same object was used for the same reason with a different set or properties in two different scenarios (you had to adjust the wrench size for different size nuts/bolts two separate jobs, but got the job done with one adjustable wrench).
The biggest challenge in OOP is thinking outside of primitives. As novice programmers, we tend to think int, float, double... and the associated values to such. But OOP is both similar and different. An object is a container of values/properties. The easiest way to truly understand an object is to understand a structure in C. You have an entity, and that entity has properties. When you use that entity, you can call one property, a set of properties, or all properties stored. If you want to get more complicated, you can stored objects within objects, and would have to iterate through the first object to access the nested objects, for the values stored in the desired object. Tricky, huh? To further understand this, I would highly recommend studying data structures.
Overload is hard to explain without confusing people. I would recommend researching it. In simplest definition, overloading is when you call the same function/method of a class, pass a different set of parameters. The parameters define which of the identically named function/methods you are calling.
Overriding is when you are quite literately calling a method of identical name and parameter, but of a child class, which invokes the use of that method over the identical method of a super class. A clean example of this is when you define a default constructor which is required in instantiating a class (for Java and C#). Another way to look at this is saying you have two classes, class 1, and class 2. You have a function/method called public int GetMe(int i) in both. To get to class 2, you must first instantiate class 1, then using that object, instantiate class 2. But instead of using GetMe(int i) in class 1, you use it in Class 2. You are overriding the GetMe(int i) method of class 1 with the GetMe(int i) method of class 2.
Encapsulation is when you use access modifiers like private, protected, etc to hide variables from super classes, but give access to change such values through methods like setters/getters.
Again, if you truly want to understand OOP, study polymorphism, overloading, overriding and encapsulation. I would also advise studying further into containers and data structures, and learn how to use iterators. You'll never ask this question again if you know these key aspects. Best of luck to you.
Edited by Subtle_Wonders, 04 February 2014 - 01:08 PM.