i know this question is asked many times on internet but here example is different which is confusing me, i was asked a question in interview about encapsulation and abstraction with real life example of t.v and remote or Air condition and remote, interviewer asked that in this example which is encapsulation and which is abstraction. Could any one describe this question?
-
The best way to describe this interview question is 'terrible' – pvg May 31 '17 at 19:33
-
@pvg could you please brief this question? the duplicated answer did not help me in this example – Mohsin AR May 31 '17 at 19:48
-
Be clear about what's confusing to you in the duplicate. Your off-the-cuff example (which isn't a bad interview question, by the way) seems to be answered rather nicely by the duplicate. If there's substantial difference between your question and that one, I'll reopen this, but you need to really justify it to me. – Makoto May 31 '17 at 20:03
-
@Makoto what is confusing me is that how can i differentiate t.v and remote with abstraction and encapsulation, suppose i say t.v is encapsulation where remote is abstraction, i know this is not acceptable answer. – Mohsin AR May 31 '17 at 20:36
-
Not sure why you think that's unacceptable; that'd probably be the answer I would go with too, given that a remote for multiple different things is abstract; each thing has to control its specific device in specific ways. Perhaps you need a bit more time to really peruse the other question? Try applying it to other real-life objects to reinforce your understanding. – Makoto May 31 '17 at 20:50
-
@Makoto i gave this same answer but interviewer said what if we lost remote, and then we can access t.v (encapsulation) directly by its buttons, isn't it violating abstraction and encapsulation?. In this point he was right isn't he ? – Mohsin AR May 31 '17 at 20:59
-
@Makoto it's a terrible interview question because the terms are already somewhat vague and the more specific one 'encapsulation' has two widely used definitions neither of which applies to real world objects. Yes you can probably sort of guess what the interviewer wanted but as a question it's awful. – pvg May 31 '17 at 21:08
-
@pvg i was not supposed to say, this question is awful, i must have to answer that question. i was really confused after interview, what answer should be of that question. now i really need answer of that question. – Mohsin AR May 31 '17 at 21:15
-
@pvg: I don't disagree that the example being used was pretty bad, but from the interviewer's perspective, it's not a bad question to ask. – Makoto May 31 '17 at 22:00
-
@mosean the problem is, the question is poor enough where it's not really possible to give all that good of an answer without interacting with the interviewer. You can look at the dupe and pick an approach you like best but any answer here would be mostly opinion-based. This makes it an off-topic question for [so]. – pvg May 31 '17 at 22:44
1 Answers
Simple definition of Encapsulation:
- The wrapping up of data and methods into a single unit(called class) is known as Encapsulation.
- The data is not accessible to the outside world and only those methods, which are wrapped in the class, can access it.
- These methods provide the interface between the objects data and the program.
- This insulation of the data from direct access by the program is called data hiding.
- Encapsulation makes it possible for objects to be treated like black boxes, each performing a specific task without any concern for internal implementation.
I think now you can understand encapsulation with TV example from the last point I mentioned.
My definition to your example is:
Functionality of the TV is hidden from you, but manufacturer of TV give you a remote controler for interacting/ or some manipulation with the TV, providing a high level of abstraction. So, you donot even know how the signal is coming from the antena and converted into a picture to be displayed on the screen before you can watch the TV.
You can see TV screen, buttons, where to plug-in and etc. But you cannot see circuits, color guns, and etc(these are data hiding).
More specifically:
According to your example, Encapsulation in both devices because of both have provided an interfaces to interact with. As a example,
powerOn()
button. But you donot know how power on when you press button in TV or remote("data hiding").
powerOn()
button also in remote controller it is a abstraction in another word remote controller has capabilities to use the interface of TV while details are hidden by encapsulation.

- 21,001
- 12
- 102
- 104
-
i don't need definition i am stuck at the question which asked about t.v and remote. – Mohsin AR May 31 '17 at 19:53
-
so you meant to say that a t.v is abstraction and remote is encapsulation ? – Mohsin AR May 31 '17 at 20:05