What is abstraction in java?
Data abstraction - in class level by using encapsulation.
Behavioral abstraction - in Inheritance level.
both are true
General meaning of Abstraction is - showing what is wanted, and hiding unwanted details. You get to see abstraction in two places.
1. Data abstraction - in class level (with encapsulation). Where encapsulations says that "wrapping up of data & behavior in such way that you restrict the direct access to couple of components" by making them private. By making them private, you are hiding the internal details of how you are storing your data. Thus achieving Data abstraction.
2. Behavior(function) abstraction - in Inheritance by using protected accessmodifer to a function. The classes in different package can't access a protected members or functions directly, unless it is inheriting your class. Thus you are hiding that functionality to other classes. This achieves a kind of Function abstraction.
This can also be put in a different words : A child gets the property of Parent. Now a friend of child asks for money. Though child is not having any money he can get it from his parent and give it to his friend. But for friend it doesn't matter from where money is coming, as it is abstracted for him.
Behavior abstraction can be explained in other ways as well:
We create a function in a class and make it public. Now every one from outside world can access our function, with out bothering about the internal implementation details of our function. This is also one kind of behavior abstraction as we are hiding the internal implementation details of our function but allowing outsiders to access that function.
Note : Abstraction is every where, it depends on how you are explaining.
Back To Top