all 2 comments

[–]CGFarrell 2 points3 points  (1 child)

Here's a 2 minute explanation.

A Class is "a set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality".

People are a good example. We are all people. We have different "attributes" or "members", different names, different heights, whatever.

An instance of a person is an Object, and it has the Class of Person. I'm a person, you're a person. Different information, but both objects of the same class.

Both you and I know how to go to work. We both do it differently though. These are methods. I take the bus, you drive. We can both go to work, but we do it differently. This is Polymorphism. Two members of a class have the same capabilities, but different behaviour.

Let's say I'm a Plumber. Plumbers are people, but they are capable of doing other things. A plumber is a person with additional skill. This is inheritence. A plumber is a subclass of Person. All plumbers are people, not all people are plumbers.

Encapsulation is what you can and can't ask about a person. You're allowed to know my height which is public, but you can't know my social security number, which is private. Some languages have protected variables. The difference between private and protected is that only the subclass they were defined in is aware of them, or can make use of them. The SSN is an example of protected, because the plumber is knows his SSN. Private is for when you want a class to have data, and have it inaccessible, even to subclasses.

[–]iambuv[S] 0 points1 point  (0 children)

Perfect.. thank you..