Write a program to apply encapsulation in Java.
Encapsulation is supported by class and protects codes from accidental damage by creating a wall around objects and hides their properties and methods. it is a protective (cap / cover / shield ) that prevents the data from being accessed by the code outside this shield.
class Change { private int l,b; public void set(int l) { this.l=l; this.b=l/3; } public void show() { System.out.println("l=="+l); System.out.println("b=="+b); } } class Client { public static void main(String[] args) { Change cc=new Change(); cc.set(70); cc.show(); } }
Encapsulation Output:
(Visited 40 times, 1 visits today)
Written by: