encapsulation 1.Encapsulation is a process of hiding all the data and methods within a class from outside world 2.Encapsulation in Java is represented using
private, package-private and protected access modifier. It wraps the
variables, method data and codes within a class into a single entity. The
class and methods outside the wrapper cannot access the code and data
defined under the wrapper. In encapsulation object becomes a container (or
capsule) for related data variables and methods. |
abstraction
2.Abstraction in Java is represented by Interface, Abstract class, Abstract methods using "abstract" keyword. It hides certain details of the object that are not important and display that are essential. In deals with the outside view of an object (interface).
|
public class table { private int width; private int height; private int length; 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)... } public static void main(String args [ ]) { table b1=new table(4,5,6); b1.displayvolume(); }
|
abstract class A { public abstract abs value(); void show() { System.out.println("This is an abstract class"); } }
|