Biology Forums - Study Force

Science-Related Homework Help Computer Studies Topic started by: emlaai on May 5, 2020



Title: What is y displayed in the following code?public class Test1 { public static void main(String[] ...
Post by: emlaai on May 5, 2020
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);
}
}


▸ y is 0.

▸ y is 2 because x + 1 is assigned to x and then x is assigned to y.

▸ The program has a compile error since x is redeclared in the statement int y = x = x + 1.

▸ y is 1 because x is assigned to y first.


Title: What is y displayed in the following code?public class Test1 { public static void main(String[] ...
Post by: binva on May 5, 2020
Content hidden