Top Posters
Since Sunday
L
4
d
4
3
k
3
k
3
j
3
k
3
b
3
f
3
b
3
d
3
h
3
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 70 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
Smart ... Thanks!
wrote...

2 hours ago
Correct Slight Smile TY
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  954 People Browsing
Related Images
  
 300
  
 71
  
 263