static variable in an instance method?
Code :
public class Password {
private static String[] passwords;
public Password() {
passwords = new String[] {"123", "ABC"};
}
public boolean isPasswordAuthentic(String password) {
boolean isAuthentic = false;
for (int x = 0; x <= passwords.length - 1; x++) {
if (password.equals(passwords[x])) {
isAuthentic = true;
break;
}
}
return isAuthentic;
}
}
i have a static String array variable. why can i reference it in an instance method?
Re: static variable in an instance method?
Can or can't?
You should be able to. Static variables can be accessed from anywhere (following the rules of public, private, and protected of course), and anywhere includes inside of a non-static method.
Think of static as another "object" that's created at run time that only contains static fields and static methods. It's referenced using the Class name.
Re: static variable in an instance method?
oh Im sorry to post this , I was confused of of my java codes.. anyway thanks for the response , Im sorry again..:o