• java:打包


    包名命名规范:

    1、包名全部小写

    2、包名一般情况下是域名的倒过来写+个性命名,如:tinyphp.com,就写成com.tinyphp+.xxx

    打包方法

    package + 包名

    package test;    
    class Test
    {
    ..
    }

    尝试打包

    cmd运行上面的代码:

    E:d>javac -d . Test.java

    就会生成一个test文件夹

    -d 就是目录的意思,directory," . "是当前目录

    调用类的路径也会改变,格式:"包名"+"."+"类名"

    E:d>java test.Test

    实例使用:

    Dog.java

    package animal;
    public class Dog{
        public void fun(){
            System.out.println("ok");
        }
    }

    Test.java

    class Test{
        public static void main(String args[]){
            animal.Dog d= new animal.Dog();
        }
    }

     或用import先导入类:再使用的时候就不用包名了

    import animal.*;  这样就可以导入该包所有的类

    import animal.Dog;
    class Test{
        public static void main(String args[]){
            Dog d= new Dog();
        }
    }

    调用包的权限问题:

    http://www.cnblogs.com/tinyphp/p/3720031.html

  • 相关阅读:
    pytest_04
    pytest_03
    pytest_02
    CF 1416C XOR Trie
    CF 1413D
    ZOJ 3725 概率dp
    ZOJ 3726
    位运算
    CF1439C 线段树
    unordered_set
  • 原文地址:https://www.cnblogs.com/tinyphp/p/3718436.html
Copyright © 2020-2023  润新知