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.