Top Posters
Since Sunday
1
1
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 68 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
Thanks
wrote...

Yesterday
Correct Slight Smile TY
wrote...

2 hours ago
Good timing, thanks!
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  862 People Browsing
Related Images
  
 305
  
 898
  
 299
Your Opinion