How to compile packages in java?

前端 未结 4 1851
深忆病人
深忆病人 2020-12-01 01:55

I have written a simple package program:


  //A simple package

       package MyPack


       class Balance
       {
        String name;
        doubl         


        
4条回答
  •  死守一世寂寞
    2020-12-01 02:06

    Best is to compile and run the classes from outside the packages :

    First you compile with javac :

    $javac MyPack/AccountBalance.java
    

    this will create a new file in the MyPack folder called AccountBalance.class

    then you can run it :

    $java MyPack.AccountBalance
    

    By the way: it is discouraged to have package names start with a capital.

提交回复
热议问题