What is y displayed in the following code?

```
public class Test1 {
public static void main(String[] args) {
int x = 1;
int y = x = x + 1;
System.out.println("y is " + y);
}
}
```
a. y is 0.
b. y is 1 because x is assigned to y first.
c. y is 2 because x + 1 is assigned to x and then x is assigned to y.
d. The program has a compile error since x is redeclared in the statement int y = x = x + 1.


c. y is 2 because x + 1 is assigned to x and then x is assigned to y.
The = operator is right-associative.

Computer Science & Information Technology

You might also like to view...

Which of the following is an example of a wireless technology?

a. 802.11a b. 802.11g c. 802.11n d. All of these answers are correct.

Computer Science & Information Technology

________________ text is defined to display the contents of a variable.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Which of the following statements about dynamic linking is false?

a) References to external functions are not resolved until a process issues calls to the functions. b) A dynamically linked program must be relinked when a library that is uses is modified. c) Shared library code can be stored separately from other program code. d) Dynamic linking saves space on secondary storage, as only a single copy of a shared library must be stored.

Computer Science & Information Technology

After the resource data has been entered into a project, you can start assigning resources to specific tasks.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology