The code is simple to understand if you know the wait-notify concept. The reason total becomes 45 is in the for loop in the run method you add i to total. So its like doing 1+2+3+4+5+6+7+8+9 which is 45.
At line 17 if you replace a with new A(), then you'll hold a lock on a different object and call wait on a different object (at line 21). The current thread needs to hold the lock on an object on which you call wait or notify...
(PS: as per the new objectives on Oracle's website, wait-notify is not on the exam anymore)
Remember what happen when we do
it will create a new thread that created thread will call the run method when it gets instantiated.
so the lines after line a.start() continue on exceuting because may be run method has not been started till yet.
If you remove a.wait() and also try/catch block,then JVM will not wait for run to get completed and output may be different each time you run the program.