Top Posters
Since Sunday
5
k
4
c
4
M
3
t
3
i
3
B
3
k
3
m
3
c
3
o
3
l
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 67 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
Brilliant
wrote...

Yesterday
Thanks
wrote...

2 hours ago
Just got PERFECT on my quiz
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  952 People Browsing
Related Images
  
 293
  
 297
  
 4797
Your Opinion
Which is the best fuel for late night cramming?
Votes: 146