What is different Private data use get, set method and public data? For example:
Class Ex1
private int val = 0
private int getVal(){ return val }
==================================
Class Ex2
public int val = 0
===================================
If we want to reach val
of Class Ex1
, we make object and call getVal()
method.
However, val
Class Ex2
just make object, and call that. Finally, they results are same, I know private , public protect used for secure, but I don't know what makes private has more secure than public.