File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes a doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "a doubt" Watch "a doubt" New topic

a doubt

ranjan sarkar

Joined: Jun 30, 2008
Posts: 7
class name
{public static void main(String[] args)
{int a=30;


gives something unexpected output.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
That output is correct. See this recentthread
ranjan sarkar

Joined: Jun 30, 2008
Posts: 7
but i need the perfect explanation.
please help me out
Henry Wong

Joined: Sep 28, 2004
Posts: 20535

Originally posted by RANJAN SARKAR:
but i need the perfect explanation.
please help me out

What is not "perfect" about the explanation? The links explains it to the full detail.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

it would also help, generally speaking, if you would explain what YOU think the output should be. Many people here will look at that and think "30 is exactly what I'd expect the output to be."

at that point, they then have to try and guess what you think the output should be, which can lead to all kinds of trouble.

if you say "Well, i think THIS should be the output, and here's WHY", it's much easier for someone to reply with "well, you make a false assumption HERE, and your logic is wrong THERE".

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ryan James

Joined: Apr 18, 2007
Posts: 15
I'd imagine he think the output should be 31, having set 'a' at 30 and then assuming the a++ will add one.
I agree. Here's the link:
subject: a doubt
It's not a secret anymore!