Abstraction Vs EncapsulationJava is an object-oriented programming language and it follows OOPs concepts. The OOPs concepts include classes, objects, polymorphism, inheritance. There are two other features of OOPs i.e. abstraction and encapsulation. They both seem very similar but totally different in concept and implementation. The major difference between abstraction and encapsulation is that abstraction hides the code complexity while encapsulation hides the internal working from the outside world. In this section, we will discuss abstraction and encapsulation and the differences between abstraction and encapsulation in Java. AbstractionIt is a feature of OOPs. It is used to hide the unnecessary information or data from the user but shows the essential data that is useful for the user. It can be achieved by using the interface and the abstract class. In interfaces, only the methods are exposed to the end-user. The best example of abstraction is a TV remote. The user only interacts with the outer interface that is nothing but keys. The user only knows which key to press for what function. Let's understand the abstraction through a Java program. EncapsulationIt is also a feature of OOP. It is used to bind up the data into a single unit called class. It provides the mechanism which is known as data hiding. It is an important feature of OOPs. It prevents to access data members from the outside of the class. It is also necessary from the security point of view. Let's understand the abstraction through a Java program. EncapsulationDemo.java Account.java Difference Between Abstraction and Encapsulation
Next TopicTop 10 Java Books |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India