java packages: cannot find symbol

后端 未结 2 529
鱼传尺愫
鱼传尺愫 2020-12-06 08:14

I\'m having a strange error. I have 2 classes in the same package but they can\'t find each other. From what I remember, as long as the classes are in the same package, they

2条回答
  •  执笔经年
    2020-12-06 08:52

    It should be:

    A.java

    package com.mypackage;
    class A {
        public static int read(){
           //some code
        }
    }
    

    B.java

    package com.mypackage;
    class B {
        public static void main(String args[]){
           int x = A.read();
        }
    }
    

提交回复
热议问题