Originally Posted by
animesh.chatterjee
Abstraction uses in order to do some works easierly. For example, you have a abstract class fruit. And fruit has some methods one of which has to be abstract . So you should fill the body of this method's body for your each class who are subclass of this abstract class.THe purpoose of it is that to implement method according to that class.
Abstraction is the process of hiding the details and exposing only the essential features of a particular concept or object.
Programming is managing complexity. whenwe uses abstraction as a tool for managing complexity in our java pro..
Encapsulation is the ability of an object to be a container (or capsule) for related properties (ie. data variables) and methods (ie. functions). Programs written in older languages did not enforce any property/method relationship. This often resulted in side effects where variables had their contents changed or reused in unexpected ways and 'spaghetti' code (branching into procedures from external points) that was difficult to unravel, understand and maintain. Encapsulation is one of three fundamental principles within object oriented programming languages.
Data hiding is the ability of objects to shield variables from external access. These private variables can only be seen or modified by use of object accessor and mutator methods. This permits validity checking at run time. Access to other object variables can be allowed but with tight control on how it is done. Methods can also be completely hidden from external use. Those that are made visible externally can only be called by using the object's front door (ie. there is no 'goto' branching concept).
public class Box
{
// what are the properties or fields
private int length;
private int width;
private int height;
// what are the actions or methods
public void setLength(int p)
{length = p;}
public void setWidth(int p)
{width = p;}
public void setHeight(int p)
{height = p;}
public int displayVolume()
{System.out.println(length*width*height);}
}
let me know if you need anymore help