Why below program is printing Object of different Array?

I am not able to understand the internal working that is happening behind the screen but I am confused because it is printing different result in console than what it is expected to. Could anybody resolve my problem with good explanation?

The sort method is working on the actual input parameter that is passed to the method by call-by-reference (I know this is not 100% correct in terms of wording - see here). That is, all changes to the array h in sortare visible in the calling code as well.

If you don't want to change the input parameter, you need to make a copy of the object. In your case you could use System.arrayCopy to do so.

Email codedump link for Why below program is printing Object of different Array?