Encapsulation and Polymorphism


Encapsulation
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. Other way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield. Polymorphism
If one task is performed in different ways, it is known as polymorphism. For example, a salesman may draw something (such as shape, triangle, rectangle, etc.) differently to convince the customer. In Java, we use method overloading and overriding to achieve polymorphism. Another example is to speak something in different ways; for example, a cat speaks meow, dog barks woof, etc.

Coupling
Coupling refers to the knowledge or information or dependency of another class. It arises when classes are aware of each other. If a class has the details information of another class, there is strong coupling. In Java, we use private, protected, and public modifiers to display the visibility level of a class, method, and field. You can use interfaces for the weaker coupling because there is no concrete implementation.




      A recent immigrant from Poland needed a drivers license, and went to the state licensing bureau.    
      When it was time for his eye test, the examiner asked him to read a chart of small letters:
W C Z E W T O S I C Z
      “Can you see that clearly and read it back to me?”    
      “Can I read it?” said the immigrant. “That guy is my best friend.”