Where data abstraction used ?

Can you please explain the oops concepts with example program? like in which place data abstraction is used?

Showing Answers 1 - 1 of 1 Answers

snyder

  • Mar 7th, 2012
 

Abstraction is a concept in which the complexity of the system is hidden from the user and the user interacts with the system via interfaces.

the simplest example of this concept is ur computer or laptop ur currently working on . . .u may not know how its electronic circuit is arranged or how many capacitors are in there or u may not even know the model no. of ur processor . . . .but still you know how to operate it and you use it very easily each and every day. . . that is the beauty of abstraction.

Here is a code in java which simulates a counter . . . for simplicity i am showing only declaration of methods

Now a user can easily use it by 1)Creating an object of Counter type and 2)Calling the methods , He doesn't need to know the how the stuff works or he may not even be a programmer and may use a GUI for the same purpose.This is know as data abstraction i.e. hiding the complex code part from the user.

In simple words data abstraction makes the life of users like heaven but on the other hand they make our(Programmers) life like hell on earth. ;)

Code
  1. public class Counter{

  2. Counter(String id); //create a counter name id

  3. void increment(int n);  //increment the counter by n

  4. int tally();  //number of increments since creation

  5. String toString(); //string representation

  6. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions