Because as per the problem statement, it is given that getConnection() throws ClassNotFoundException. The code that you have posted here doesn't do that. Please post complete code that you are trying to run.
This is a really tricky question. I had to run a couple of times and am still struggling with it.
So :
1. if an exception is thrown before the try-catch-with-resource block(inside try() for example) for example FileNotFoundException then the caller will get Exception
2. if an exception is thrown inside a try-catch-with-resources block, for example, ClassNotFoundException then this is what the caller will get BUT, if something happens after the try-block return, on close for example an IOException, then IOException will be added as a suppressed warning into ClassNotFoundException and the caller will get ClassNotFoundException