简体   繁体   English

从同一目录中的另一个 class 访问公共 class 变量

[英]Accessing the public class variable from another class in same directory

I've come across a java code in which the method aw_best_tour_index() of public class Utilities access the variable of the class InOut which is public .我遇到了一个 java 代码,其中公共 class 实用程序的方法aw_best_tour_index()访问 class InOut的变量是public的。 The variables of the class InOut are best_in_try and max_index . class InOut的变量是best_in_trymax_index They've been called in the method like this:他们在这样的方法中被调用:

final int[] values = InOut.best_in_try; and

final int l = InOut.maxindex; . .

But when I compile this using javac in command prompt it shows the error "Cannot find symbol".但是当我在命令提示符下使用 javac 编译它时,它会显示错误“找不到符号”。 What should be reason for this?这应该是什么原因?

There could be multiple problems:可能有多个问题:

  • Did you include InOut if it isn't in the same Java file如果 InOut 不在同一个 Java 文件中,您是否包括在内
  • Are the variables static变量是 static
  • If not, is InOut an instance of the class containing maxindex and best_in_try?如果不是,InOut 是否是包含 maxindex 和 best_in_try 的 class 的实例?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM