Given:
and
What is the result?
Given:
and
What is the result?
First, the constructor of the Resource class is called, which prints 'A'. Then, the printResource method is called, which prints 'C'. After the try block is finished, the close method is called automatically because the Resource class implements AutoCloseable, which prints 'B'. Finally, the code in the finally block is executed, which prints 'D'. The final output is 'ACBD'.
C IS CORRECT 1- new resource() print -> A 2- r.printResource() print C 3- close is called when try blick is finished so PRINT B 4- finally print D