File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confused with static code " Watch "confused with static code " New topic
Author

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 {

static{
int x=5;
}
static int x,y;

public static void main(String[] args) {

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

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

Joined: Feb 23, 2007
Posts: 447
Hi

Discussed Few Days before...

Check here


Thanks

Anil Kumar
Abdullah Mamun
Ranch Hand

Joined: Mar 19, 2007
Posts: 99

Hi Anita dhar

You might want to read this excellent article.


MooN
Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
Thanks it was really useful
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confused with static code