What is the result?

Given:

What is the result?
A. Compilation fails.
B. 3 5
C. 0 0
D. 9 25

Download Printable PDF. VALID exam to help you PASS.

2 thoughts on “What is the result?

  1. Answer B:

    The int x and int y that were declared and initialized within the main() method are local fields. And since the local fields have exactly same names as the instance fields (i.e. the int x and int y that where declared after the class definition), then the local fields shadows the instance fields. Accordingly, the println() method takes the x and y of the main() method.

    The println() method can print the instance fields in case we use different names of the local variables x and y.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.