Take the 2-minute tour ×

Here are the brief definitions of encapsulation and abstraction.


The process of abstraction in Java is used to hide certain details and only show the essential features of the object. In other words, it deals with the outside view of an object (interface). The only good example i see for this across different sites is interface.


Its basically about hiding the state of object with the help of modifiers like private,public,protected etc. we expose the state thru public methods only if require.

What we achieve with modifiers like private, public also hides unnecessary details from out side world which is nothing but also a abstraction concept

So, from above explanation looks like encapsulation is a part of abstraction or we can say its a subset of abstraction. But why then encapsulation term is invented when we could deal it with abstraction only? I am sure there should be some major difference which distinguishes them but most of material on net says almost same thing for both of them.

Though this question has been raised on this forum earlier too but i posting it again with specific doubts.Some replies also says abstraction is a concept and encapsulation is implementation.But i don't buy this > if it is true I can think these two different concepts are provided to confuse us.

share|improve this question
encapsulation as defined above is a tool of abstraction however I tend to think of it in terms as what a class encapsulates (functionality/data regardless of access) where as abstraction is more a sense of removing you from concerns of concrete implementations i.e. regardless of how it is done and what exactly is done it is doable from wikipedia An 'abstraction' (noun) is a concept that acts as a super-categorical noun for all subordinate concepts, and connects any related concepts as a group, field, or category. –  T I Jan 22 '12 at 12:22
add comment

5 Answers

up vote 14 down vote accepted


Abstraction is a more generic term, it can also be achieved by (amongst others) subclassing. For example, the class List in the standard library is an abstraction for a sequence of items, indexed by their position, concrete examples of a List are an ArrayList or a LinkedList. Code that interacts with a List abstracts over the detail of which kind of a list it is using.

Abstraction is often not possible without hiding underlying state by encapsulation - if a class exposes its internal state, it can't change its inner workings, and thus cannot be abstracted.

share|improve this answer
add comment

Abstraction is the concept of describing something in simpler terms, i.e abstracting away the details, in order to focus on what is important (This is also seen in abstract art, for example, where the artist focuses on the building blocks of images, such as colour or shapes). The same idea translates to OOP by using an inheritance hierarchy, where more abstract concepts are at the top and more concrete ideas, at the bottom, build upon their abstractions. At its most abstract level there is no implementation details at all and perhaps very few commonalities, which are added as the abstraction decreases.

As an example, at the top might be an interface with a single method, then the next level, provides several abstract classes, which may or may not fill in some of the details about the top level, but branches by adding their own abstract methods, then for each of these abstract classes are concrete classes providing implementations of all the remaining methods.

Encapsulation is a technique. It may or may not be for aiding in abstraction, but it is certainly about information hiding and/or organisation. It demands data and functions be grouped in some way - of course good OOP practice demands that they should be grouped by abstraction. However, there are other uses which just aid in maintainability etc.

share|improve this answer
add comment


They are different concepts.


    E.g. for a person: you decide to keep first and last name and SSN. Age, height, weight etc are ignored as irrelevant.

    Abstraction is where your design starts.

  • Encapsulation is the next step where it recognizes operations suitable on the attributes you accepted to keep during the abstraction process. It is the association of the data with the operation that act upon them.
    I.e. data and methods are bundled together.
share|improve this answer
Can we say Abstraction is a kind of design concept and Encapsulation mainly concerns about implementation of design we agreed upon during abstraction? –  M Sach Jan 22 '12 at 12:36
In encapsulation you define operations that can/must be applied to your data.This can be part of the design as well.E.g. retrieve SSN, but not modify it –  Cratylus Jan 22 '12 at 13:18
stackoverflow.com/a/16939575/2401223 –  Aparan Jun 5 '13 at 12:33
add comment

Abstraction is a very general term, and abstraction in software is not limited to object-oriented languages. A dictionary definition: "the act of considering something as a general quality or characteristic, apart from concrete realities, specific objects, or actual instances".

Assembly language can be thought of as an abstraction of machine code -- assembly expresses the essential details and structure of the machine code, but frees you from having to think about the opcodes used, the layout of the code in memory, making jumps go to the right address, etc.

Your operating system's API is an abstraction of the underlying machine. Your compiler provides a layer of abstraction which shields you from the details of assembly language. The TCP/IP stack built into your operating system abstracts away the details of transmitting bits over a network. If you go down all the way to the raw silicon, the people who designed your CPU did so using circuit diagrams written in terms of "diodes" and "transistors", which are abstractions of how electrons travel through semiconductor crystals.

In software, everything is an abstraction. We build programs which simulate or model some aspect of reality, but by necessity our models always abstract away some details of the "real thing". We build layer on layer on layer of abstractions, because it is the only way we get anything done. (Imagine you were trying to make, say, a sudoku solver, and you had to design it using only semiconductor crystals. "OK, I need a piece of N-type silicon here...")

In comparison, "encapsulation" is a very specific and limited term. Some of the other answers to this question have already given good definitions for it.

share|improve this answer
add comment

NOTE: I am sharing this. It is not mean that here is not good answer but because I easily understood.


When a class is conceptualized, what are the properties we can have in it given the context. If we are designing a class Animal in the context of a zoo, it is important that we have an attribute as animalType to describe domestic or wild. This attribute may not make sense when we design the class in a different context.

Similarly, what are the behaviors we are going to have in the class? Abstraction is also applied here. What is necessary to have here and what will be an overdose? Then we cut off some information from the class. This process is applying abstraction.

When we ask for difference between encapsulation and abstraction, I would say, encapsulation uses abstraction as a concept. So then, is it only encapsulation. No, abstraction is even a concept applied as part of inheritance and polymorphism.

Go here for more explanation about this topic.

share|improve this answer
add comment

Your Answer


