private
and writing public
methods in the class to set and get the values of variables.
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. |
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.