And check out line 13. Are you sure that is the m want to assign the value to?
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
The reason you got 0 the first time was that you had the keyword int before the name of the variable (I think it was m). That means you are creating a new local variable m which “shadows” the field of the same name. You change the local m and leave the field unchanged.
Whoever said "overflow" was correct. If you google, you find this, for example. The pictures are helpful.
the code you have mentioned in line 17 there is a mistake
mehe a= new meh(500,14000,1000) ;
change mehe to meh.
and the reason why it returns the value of "m" 0(Zero) when you print it because you have made it static and static variables are loaded when the first time class name has been called and it can't see Instance Variable or non static methods.
And by default value of int is assigned 0(Zero), that's why you are getting Zero when you try to print that
I hope now the things will be more clearer and understandable to you.
"The More you Play With it, The more you will learn. Keep Playing"
Tarun wadhwa wrote: . . . and the reason why it returns the value of "m" 0(Zero) when you print it because you have made it static and static variables are loaded when the first time class name has been called and it can't see Instance Variable or non static methods. . . .
Nonsense. That is quite mistaken.
The reason for getting 0 printed was that m was shadowed by the mistaken declaration of a local variable.
Wouter Oet, Sean Clark and I have already told you that, some of us more clearly than others.
Apology accepted The important bit: can you see what the mistake was, and remember it for next time? Mistakes are not serious, as long as they are found and corrected. That is why you are here: to get rid of mistakes and misconceptions.
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Free, earth friendly heat - from the CodeRanch trailboss