In OOPs, Abstraction is that the method of getting info. the information needed will be taken in such the simplest way that solely the required components are extracted, and also the ones that are considered less significant are unnoticed. Or the unessential info will be drained dead set keep solely the sensitive information intact. during this case, most of the classes don’t have any sort of implementation, and most of the problem-solving method is completed at the interface stage. one thing that doesn’t exist and is just a concept is named Abstraction. In abstraction, implementation complexities are hidden using abstract classes and interfaces.
Example of Abstraction:
Sum of the two number is: 9
In the this example, we can see that abstraction has achieved by using class. The class 'Summation' holds the private members a, b and c, which are only accessible by the member functions of that class.
Encapsulation is the process or method to contain the information. The info, it provides is that the solely the one that is critical and every one the opposite data that is unsuitable is hidden already. during this case, the matter determination is completed at the stage of implementation. Encapsulation is a method to hide the data in a single entity or unit along with a method to protect information from outside. Encapsulation keeps something in an exceedingly capsule and showing of solely the essential options of a product. for example, once someone is mistreatment software package they are doing not recognize what the secret writing is, they solely use the mandatory functions that result from the secret writing that is unbroken safe within the files.
Example of Encapsulation:
In the this program, the variable a is made private so that this variable can be accessed and manipulated only by using the methods get() and set() that are present within the class. Therefore we can say that, the variable a and the methods set() as well as get() have binded together that is nothing but encapsulation.
Difference between Abstraction and Encapsulation:
|1.||Abstraction is the process or method of gaining the information.||While encapsulation is the process or method to contain the information.|
|2.||In abstraction, problems are solved at the design or interface level.||While in encapsulation, problems are solved at the implementation level.|
|3.||Abstraction is the method of hiding the unwanted information.||Whereas encapsulation is a method to hide the data in a single entity or unit along with a method to protect information from outside.|
|4.||We can implement abstraction using abstract class and interfaces.||Whereas encapsulation can be implemented using by access modifier i.e. private, protected and public.|
|5.||In abstraction, implementation complexities are hidden using abstract classes and interfaces.||While in encapsulation, the data is hidden using methods of getters and setters.|
|6.||The objects that help to perform abstraction are encapsulated.||Whereas the objects that result in encapsulation need not be abstracted.|
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between Abstraction and Encapsulation in Java with Examples
- Abstraction in C++
- Encapsulation in C++
- Difference and Similarities between PHP and C
- Difference between Stop and Wait protocol and Sliding Window protocol
- Similarities and Difference between Java and C++
- Difference between Yaacomo and and XAP
- Difference between VoIP and and POTS
- Difference between "int main()" and "int main(void)" in C/C++?
- Difference between ++*p, *p++ and *++p
- Difference Between DOS and Windows
- Difference between User Level thread and Kernel Level thread
- What’s difference between The Internet and The Web ?
- Difference between Priority Inversion and Priority Inheritance
- What’s difference between Linux and Android ?
- What’s difference between header files "stdio.h" and "stdlib.h" ?
- Difference between HTML and HTTP
- Difference between http:// and https://
- What's difference between MMU and MPU?
- What's difference between Microcontroller (µC) and Microprocessor (µP)?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.