+ 6

What is meant by abstraction?

I've looked it up on the internet and it says "Abstraction is the process of abstraction in Java is used to hide certain details and only show the essential features of the object".But, details can be hidden by making a variable private which comes under encapsulation according to my knowledge. so what's the difference between encapsulation and abstraction?

18th Jan 2018, 5:34 PM
Hope
Hope - avatar
2 Respuestas
+ 4
This is a confusing topic that not many books are successful to clear, so please allow me to try. Encapsulation in any Object Oriented Programming language like Java or C# is about restricting (or not) the access to class members (variables, methods) from out side the class owner of those members, by declaring them public, default, protected or public. Abstraction is a technique used as a "contract" which declares functionalities or properties that must be implemented in every concrete (non-abstract) class that inherits from that Abstract Class or Interface. Let me focus on Interfaces to explain this. Interfaces are abstract by default, in them you declare methods by providing only the signature (access level, return type, name and parameters, and ends with semicolon) without a body (not even "{}"), and every class that implement this Interface must implement (redundant, i know) all the methods declared on that Interface by providing a body or logic to it as you would to any other normal method. The difference between an Abstract Class and an Interface (in case you were wondering) is regarding inheritance handling, and any variable declared in an Interface is a constant (FINAL) by default. I honestly hope this helps Amit.
18th Jan 2018, 6:25 PM
Roberto Guisarre
Roberto Guisarre - avatar
+ 3
They hide different things. Encapsulation means that the internal representation of an object is hidden from the outside, i.e. encapsulation hides information. Abstraction is a way to represent the essential features without including implementation details. i.e. it hides the implementation from other objects.
18th Jan 2018, 6:57 PM
Desi Borisova
Desi Borisova - avatar