0

Can you give me some examples for encapsulation in Java?

I want learn and see this from different perspectives =}

20th May 2018, 7:10 PM
Sympthom
Sympthom - avatar
4 Respuestas
+ 1
class Employee { private String name; public String getName() { return name; } public void setName(String name) { this.name=name; } } class Demo { public static void main(String[] args) { Employee e=new Employee(); e.setName("Harry"); System.out.println(e.getName()); } } ok I'm providing basic code for encapsulation but you should try your own and show me once when you get the knowledge of this topic here in above code employee details are bind in an class which is secure from outside of the class
20th May 2018, 7:26 PM
MsJ
MsJ - avatar
0
Encapsulation:It is actually the process of binding data members and methods together in a unit.Each class in java itself is an example of encapsulation .( it is just like the knowledge as we all make any code by our knowledge of the language and then by making all syntax we make code to solve a problem) to binds the inner constituents into a unit to make it safe from misuse. so to solve a problem what ingredients required which held safe from outer class or world is encapsulation
20th May 2018, 7:20 PM
MsJ
MsJ - avatar
0
Mohit the coder (M.S.D) no i meant code examples not definition. but thanks anyway!
20th May 2018, 7:21 PM
Sympthom
Sympthom - avatar
0
Ye thanks, i am just trying to understand it
20th May 2018, 7:26 PM
Sympthom
Sympthom - avatar