in the below program i understand that the processing starts from the right side
so in the first accept method 5 is printed and incremented to 6.
and the andthen method is suppose to print 6. However the output that i get is 56.
Can someone please clarify.
You have an object of type Consumer which you call andThen() on, which yields a new Consumer. That resulting consumer can succinctly be described as "print and then print". In other words, it prints what you give to it twice.
i++ returns 5, so passing it to your consumer that prints its argument twice will result in "55" being printed.