Multiple classes in a single Java file, each with a main method - unexpected behavior?

前端 未结 3 536
时光取名叫无心
时光取名叫无心 2021-01-13 16:06

I have got the following code in a file called test.java which is located inside the directory C:\\D\\JavaProjects

class test
{
        public static void ma         


        
相关标签:
3条回答
  • 2021-01-13 16:16

    use public (then class name).... that will definetely work....

    0 讨论(0)
  • 2021-01-13 16:21

    Presumably you're running on Windows, right?

    That means you can't have two classes which differ only in case - because they'll both end up wanting to be in the same file, as Test.class and test.class are effectively the same filename in case-insensitive file systems.

    It's not really a bug in Java - just an unfortunate but natural corollary of using a case-insensitive file system in conjunction with a language which attaches meaning to filenames.

    0 讨论(0)
  • 2021-01-13 16:28

    @dark_secrets, You have to begin a class name with a capital letter in JAVA or else you will get an error while compiling.

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