This is very basic and important question asked in many Java interviews. This question is basically asked to check if candidate have a good understanding of OOP's (Object Oriented Programming) concepts or not.
Abstraction - In very simple words Abstraction is concept of hiding complexity of a system and showing only necessary details to its user. So user can access the necessary functionalities easily without thinking of internal complexity of the system. Abstraction mainly focus on outside view or design of the system.
In real word scenarios we can take an example of a mobile phone. In mobile we as a user only see's the necessary details or features like screen, buttons etc. and all other complexities (circuits, chips and internal wiring etc) are hidden from us.
In Java programming abstraction is implemented through interfaces and abstract classes.
Encapsulation - Encapsulation is a process of binding members (attributes) and functions (methods) in a single entity, so that they can be protected from outsiders. Encapsulation mainly focus on internal design of a system.
In real word scenarios we can take the same mobile phone example, where after binding all attributes and functionality we call it a mobile phone. And after encapsulating everything in a single entity it is safe from outsiders.
In Java programming encapsulation is implemented through class and access modifiers. We encapsulates attributes and methods in a single entity which is called class and we can use access modifiers (public, private, protected and default) to provide different protection levels to internal attributes, methods or the class itself.
Check below links also-
_________________________________________________
***********************Keep studying***********************
Nicely explained. Keep up writing more of such articles :)
ReplyDeleteThanks Babuli
ReplyDelete