Calling static method from another java class

前端 未结 3 1573
执笔经年
执笔经年 2020-11-28 15:14

I\'ve recently switched from working in PHP to Java and have a query. Want to emphasise I\'m a beginner in Java.

Essentially I am working in File A (with class A) a

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 15:36

    Ensure you have proper access to B.staticMethod. Perhaps declare it as

    public static String[] staticMethod() {
        //code
    }
    

    Also, you need to import class B

    import foo.bar.B; // use fully qualified path foo.bar.B
    
    public class A {
        String[] lists = B.staticMethod();
    }
    

提交回复
热议问题