Java Puzzle – private fields
Will following program work ?
class MyClass{private int privateId = 101;public static void main(String[] args){System.out.println("Hello World!");new MyClass().doStuff(new MyClass());}public void doStuff(MyClass obj){//accessing private instance variableSystem.out.println(obj.privateId);}}
Oh Yes definitely
ReplyDeleteNeil you are 100% right .
ReplyDeleteMany other are also able to catch it.
ReplyDeleteActually Any private fields can be accessed by instance of same class in the same class.