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 69 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
This calls for a celebration Person Raising Both Hands in Celebration
wrote...

Yesterday
Thanks
wrote...

2 hours ago
Thanks for your help!!
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  847 People Browsing
Related Images
  
 502
  
 278
  
 851
Your Opinion
Do you believe in global warming?
Votes: 422