File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confused with static code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confused with static code " Watch "confused with static code " New topic

confused with static code

anita dhar
Ranch Hand

Joined: Jul 14, 2007
Posts: 69
can anyone please explain me why the output is 3.And x-- should be 0.since it changes to 1 only in next place of x right ,as it is a post increment..Am i right ...Please explain this.

public class sample12 {

int x=5;
static int x,y;

public static void main(String[] args) {

System.out.println(x+y + ++x);

public static void myMethod(){
y=x++ + ++x;
anil kumar
Ranch Hand

Joined: Feb 23, 2007
Posts: 447

Discussed Few Days before...

Check here


Anil Kumar
Abdullah Mamun
Ranch Hand

Joined: Mar 19, 2007
Posts: 99

Hi Anita dhar

You might want to read this excellent article.

Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
Thanks it was really useful
I agree. Here's the link:
subject: confused with static code
It's not a secret anymore!