简体   繁体   中英

How I can compile a java file using a class in a separate file

and a little confused about the compile process:

There's my file structure

bin/ test/A.java test/B.java

# B.java

package test; 
private class B{
    public static void say(){
        System.out.println("Hello.");
    };
}



# A.java

package test;
public class A{
    public static void main(String arg[]){
        test.B.say();
    }
}

then I compile A.java

javac -cp test/*.java test/A.java

It gives me error:

test/A.java:4: cannot find symbol
symbol  : class B
location: package test
        test.B.say();
            ^
1 error

B should be a public class not a private class. Changing from private class B to public class B works out and compiles successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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