This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
HI,
Please let me know waht is the difference between declaring variables at line no.1 and line no. 2
I thought declaring a variables in the constructor Employee constructor will make the variable for the method getName(). but the same did not happen.
I am a bit confused with instance variable concept. Instance variable are accessible through the object of the class. So I declared it in the constructor itself. Now tha same variable is not accessible outside the constructor in the same class to other methods.
The variable @ line #12 are local variables visible only to the constructor block. Instance variables should be declared outside any method / block in the class. So try declaring the variables @ line #5.
The constructor in no different than any other method or code block in terms of scope, variables declared inside a constructor or any other codeblock are not visible outside it. You should move the declaration of name outside the constructor while still giving it value of 'n' inside it.
Campbell Ritchie wrote: . . . and why are you suppressing a deprecation warning? That looks suspicious to me.
Likewise. The getMonth() method of java.util.Date was deprecated some time ago (JDK 1.1, lol, that's some serious backwards compatibility right there).