0
Can we call a instance variable in a static method other than static main ,how?
6 Respostas
0
Edit: You can't call a instance variable even inside the main method without creating an instance of the class.
But you can always create a variable with the same name as instance variable inside a static method, this process is called shadowing.
Non-static variables are not accessible inside the static context.
0
but i can call a instance variable in a static main by first creating a object //A ref=new A();
and then ref.variable name //
this can be done right?
0
Yes because you are accessing with the help of an object.
0
What ever, you are able to in main method, you can do it in any other static methods...
0
jaya krishna are you saying that I need to create a object for that.
0
Yes. In same way as it possible in main method..