Top Posters
Since Sunday
j
3
s
3
j
2
J
2
e
2
n
2
t
2
d
2
b
2
t
2
J
2
b
2
New Topic  
emlaai emlaai
wrote...
Posts: 443
4 years ago
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.
Textbook 
Introduction to Java Programming, Comprehensive Version

Introduction to Java Programming, Comprehensive Version


Edition: 10th
Author:
Read 81 times
1 Reply
Replies
Answer verified by a subject expert
binvabinva
wrote...
Posts: 369
4 years ago
Sign in or Sign up in seconds to unlock everything for free
More solutions for this book are available here
1

Related Topics

emlaai Author
wrote...

4 years ago
Helped a lot
wrote...

Yesterday
Thanks
wrote...

2 hours ago
Thanks
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  866 People Browsing
Related Images
  
 82
  
 401
  
 1157