java - 从其他包访问非公共(public)类

标签 java

我在包序列中有一个 Logistic 类

 package sequence;

 class LogisticSeq  {

 int limit;                                         
 double lamda;                                      
 ArrayList <Double> lseq = new ArrayList <Double>();         

 LogisticSeq(int a, double b, double c) {
    limit = a;
    lseq.add(b);
    lamda = c;      }

 void sequence() throws IOException{

     File file = new File("Sequence.txt");  
     if (!file.exists()) {
        file.createNewFile();
        }}

  public class Logistic {

    public static void main (String[] args) throws IOException {
    LogisticSeq L = new LogisticSeq(50,0.4999,3.9999); 
    L.logisticsequence();
 }

如何从其他包中的类访问LogisticSeq类

最佳答案

你说:

@Hovercraft Full Of Eels I tried to change it to public but i got the error in eclipse and says to define it in its own file.

听起来您要么将 LogisticSeq 类放在一个包含多个类的文件中,要么您的类/包名称与项目的包/文件结构不匹配。

我建议您按照 Java 编译器告诉您的去做:在序列包中创建一个 LogisticSeq.java 文件,并确保该类是公共(public)的。

关于java - 从其他包访问非公共(public)类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21218987/

相关文章:

java - 如何访问 rx 中先前发射的数据?

Java改变颜色JLabel

java - 删除列表的一部分并在成功时返回 true 的方法的正确语法是什么?

c# - C# 中的控制台窗口?

java - 调用 JvmModelInferrer/Generator 从 Java 项目生成代码时出现 NullPointerException

java - java Rest请求时偶尔出现"407 Proxy Authentication Required"错误

java.security.NoSuchAlgorithmException : SHA224withRSA Signature not available Java 7

java - spring boot 获取url参数的方法

java - 如何确保 hibernate 5 在与共享主键的一对一关系中以正确的顺序持续存在

java - 在 Java servlet 中,cookie.getMaxAge() 总是返回 -1