since initially p is ref to System.out so 2 and 3 will go to console, than p1 is referred to test.txt so 4 will go to test, similarly p is still referring to System.out so again 5 and 6 will go to console. now setOut is taking argument as p1 but i didn't understand what it means. Does that means like set the output of reference of type System to the destination which is referred by p1. if it is so than ok it will produce 9 in the test.txt and 10 in the console. but if it doesn't mean that, than please tell me the concept. Actually please tell me what exactly is this statement doing:-