What is the difference between public void and void methods?

This question already has an answer here:

  • In Java, difference between package private, public, protected, and private 26 answers

  • This has already been answered here: In Java, difference between default, public, protected, and private

    Without specification of an access modifier the access is determined by the classes location within the package hierarchy. Similar to public, but not the same by any means.


    With public void the word "public" is not a return type. The public is an access modifier in Java.

    The following table shows the access to members permitted by each modifier; there are four

    public
    (none / blank) "package" level
    protected
    private
    

    Access Levels

    |Modifier   |Class|Package|Subclass|World|
    ------------------------------------------
    |public     | Y   | Y     | Y   | Y      |
    ------------------------------------------
    |protected  | Y   | Y     | Y   | N      |
    ------------------------------------------
    |no modifier| Y   | Y     | N   | N      |
    ------------------------------------------
    |private    | Y   | N     | N   | N      |
    ------------------------------------------
    

    public is a visibility modifier, in this case there would be no limitation on which classes can access the method

    void is a return type, void means the method doesn't return anything to the caller.

    链接地址: http://www.djcxy.com/p/24072.html

    上一篇: 我可以在java的类之外访问受保护的字段

    下一篇: 公共无效和无效方法有什么区别?