Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public class Test {
int i;
int j;

public static void main(String[] args) {

Test t1 = new Test();
Test t2 = new Test();

t1.j=t2.i=5;
t1.i=t2.j=6;

System.out.print(t1.j++ + " " + t2.i--);

}
}
Posted
Comments
Member 11228096 12-Nov-14 10:38am    
Need help wrt the o/p of the above prgm ? when I compile it the answer is 5 5 . Need help in understanding how t1.j++ is 5

Because x++ is what's called a "postfix" operator: it means "get the value of x and then increase x by one but do not affect the value you fetched earlier":
C#
int temp = x;
x = x + 1;
return temp;
 
Share this answer
 
See https://docs.oracle.com/javase/tutorial/java/index.html[^], and work through it, all the answers can be found there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900