i need example for java abstraction. where we use
abstraction and why we need abstraction.

Answers were Sorted based on User's Feedback



i need example for java abstraction. where we use abstraction and why we need abstraction...

Answer / brijesh singh

basicall i need to know that u say abstration are use to hide the the unnecessary data but in c or c++ it is also done. through printf and so on we hide the unnecessary data ,so how it is the feature of oops? descrives in details plzzzzzzzz.

Is This Answer Correct ?    4 Yes 3 No

i need example for java abstraction. where we use abstraction and why we need abstraction...

Answer / pushpa

Abstraction is the hiding of information behind other,
usually simpler, information. In programming, abstraction
is often used to hide implementation or system details
behind a simple interface. For example, in the standard
C library, we open a disk file with fopen(); this hides
the details of disk I/O and system calls behind the
abstraction named "fopen".

In Java, abstraction is used specifically in the Object
Oriented Programming (OOP) sense: hiding the details of
the implementation of an object behind the interface
composed of its methods.

For example, the Java Collections Framework defines the
abstraction called java.util.Map. It is an abstract view
of a software object that maps from one set of objects
into another. The class java.util.TreeMap implements the
Map abstraction.

Abstraction in Java is mostly implemented with interfaces
and abstract classes, but you can actually implement it
anywhere that you hide details behind a method.

Here is a simple example. The abstraction of a factorial
of a positive integer N is that it is the product of N
times the factorial of (N-1). The factorial of 1 is 1.
Exactly how we compute the product is irrelevant, all that
matters is that our code obey the factorial abstraction.

public class Factorial {
public static long factorial(int x) {
if (x < 1) throw new RuntimeException("Bad X");
if (x == 1) return 1L;
else {
long y;
y = 1;
while(x > 1) {
y = y * x;
x = x - 1;
}
return y;
}
}
}

So, in this example, we computed the factorial in a
slightly different way than the definition, but it
always gives the right answer! We've hidden the details
behind an abstraction.

You can learn more about abstraction in OOP from these
articles:

http://www.kbcafe.com/articles/OOP.Concepts.pdf
http://www.campusprogram.com/reference/en/wikipedia/a/ab/abstraction__computer_s...
http://javaboutique.internet.com/tutorials/JavaOO/index.html

Is This Answer Correct ?    2 Yes 6 No

Post New Answer

More Core Java Interview Questions

how to compile jsp?

4 Answers   Logica CMG,


How is tree Mirroring implemented?

0 Answers   Fidelity,


Is it possible to compare various strings with the help of == operator? What are the risks involved?

0 Answers  


Is it possible for a yielded thread to get chance for its execution again?

0 Answers  


What is the abstraction?

0 Answers  






Explain the different forms of polymorphism?

0 Answers  


How to create an instance of a class without using "new" operator? Plz help me out properly.Thank u.

10 Answers   CSC,


What are the drawbacks of reflection?

0 Answers  


What will happen if static modifier is removed from the signature of the main method?

0 Answers  


What is the method used to get the absolute value of a number?

2 Answers  


what is business objects?

2 Answers  


what is connection pooling with example?

3 Answers   Amdocs,


Categories