# OOP Object Oriented Programming ###### tags: `Concepts` [TOC] ## Abstraction By using abstract classes we can state bases for some classes, for those methods that may differ, they can remain abstract methods, and state those which are in common for both. In other words, abstract class defines a generalization form that will be shared by all of its subclasses, leaving it to each subclass to fill in the details. Note: [Java Abstract Class V.S Java Interface](/v4O9O7WeRauPs6wCHGau7Q) ## Encapsulation When talking about encapsulation, we will think about access modifiers. Because we do not wish parameters to be too open and accesible from anywhere. Being encapsulated, makes a protective shield that prevents data being acessed by the code outside. ### Different Access Modifiers >* **Public:** Accessible in all class in your application. >* **Protected:** Accessible within the package in which it is defined and in its subclass(es)(including subclasses declared outside the package) >* **Private:** Accessible only within the class in which it is defined. >* **Default (declared/defined without using any modifier):** Accessible within same class and package within which its class is defined. [color=pink] ## Inheritance It allows one class to inherit features(fields and methods) of another class. For instance, we will have parent/child class, by having them we increase reusability and chances to check instance (If we have two items of the same parent, we can call same method without checking what class it is from). ## Polymorphism You can have same method/function but define in different ways. This one has mainly 2 types: ### 1. Overloading Overloading is meainly done when having same method but different parameters. You probably must have seen different constructors with different parameters, that is exactly one example. ### 2. Overriding Overriding mainly happens when tou have implement interface or abstract classes, or even extends a parent class. In order to change or add the main method, you use overriding to re state what you want to do.