Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can some one explain to me why the following Java codes print what they print in

ID: 3812137 • Letter: C

Question

Can some one explain to me why the following Java codes print what they print in the console? I need help tracing the code to understand the outcome.

This is a friends old study guide and he worked them out but I'm not sure what exactly he is doing.

Thanks !!!!

3. What is printed by the following code? public static class MyClass int x, y; MyClass 0 (x 2, y 4 public void Compute (int x, int y) y t this.x; i System.out.println(w), MyClass m. new My Class 0; m Compute (3, 1 (a) 10 (b) 4 (e) none of the above

Explanation / Answer

Question 3
Answer: c. 9

we are calling Compute method with parameter values 3 and 1
So x value is 3 and y value is 1
Inside Compute method, we are adding the values
x + this.y + this.x means here x value is 3 and this.x value is 2 and this.y value is 3.
When we use this key word , we are accesing the class level variables.
so 3 + 4 +2 = 9

Question 26:
Answer: b) 4

In this code, we are displaying the length of an array.
x.length will return 4. Becuase here x is two dimensional array.
x.length will give number of rows in an array and x[i].length will give number of columns in that row.
S x.length will print 4

Question 27:
Answer: d) 5

In this code, we are printing 3rd row columns.
x[2].length will give value 5.
x.length indicates the number of rows in an array
and x[i].length indicates the number of columns in a row.
Here x[2] means 3rd row. row starts from 0.
So x[2] contains 5 columns.

Question 28:
Answer: d) 8

x[2][1] means 3rd row and 2nd column value we are printing.
so value 8 will be printed.