为什么在main方法中用类的静态方法调用main方法中创建的局部变量(非static)是可以的?不是说静态方法只能调用static变量吗?求大佬解答
public class Identity {
String num = "";
public static int countDigits(String id) {
return id.length();
}
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
String string = "";
System.out.println("请输入你的身份证号:");
countDigits(string);
String id = scanner.nextLine();
System.out.println("原来你的身份证号码是" + countDigits(id) + "位数字啊");
}
}