Why can't I run my java Hello World program if it is inside a package?

前端 未结 3 1357
你的背包
你的背包 2020-12-17 19:09

I created a file called \"Hello.java\" that looks like this:

public class Hello {
        public static void main(String[] args) {
                System.out         


        
相关标签:
3条回答
  • 2020-12-17 19:17

    Now that it's in testpackage, its name is really testpackage.Hello. So go up a directory and do java on that.

    0 讨论(0)
  • 2020-12-17 19:27

    Go up one directory, and run:

    java testpackage.Hello
    
    0 讨论(0)
  • 2020-12-17 19:32

    Try java testpackage.Hello.

    Because this is in your classpath, you should be able to run that from any working directory, but refer to it by its full name.

    0 讨论(0)
提交回复
热议问题