Dosen't Reflection API break the very purpose of Data encapsulation?
Very recently I came across the Reflection API and to my surprise we can access and even alter the private variables.I tried the following code import java.lang.reflect.Field; public class SomeClass{ private String name = "John"; } public class Test{ public static void main(String args[]) throws Exception { SomeClass myClass = new SomeClass(); Field fs = myClass.getClass().getDeclaredField("name"); fs.setAccessible(true); System.out.println("Variable is " + fs.getName() + " and value is " + fs.get(myClass)); fs.set(myClass, "Sam"); System.out.println("Variable is " + fs.getName() + " and value