Access Protection

A class without any access specifier is considered with default access level. Default access is limited to package. In means a class without any access specifier can be accessed only in same package.

  • Public accessibility

    A class declared with public keyword can be accessed anywhere outside the package also.

    Example :

    
    package app; 
    public class demo
    {
    void clear()
    {
    System.out.println("clear method");
    }
    }

    class demo can be accessed anywhere.


  • Default accessibility

    A class declared without any access specifier can be accessed only in same package.

    Example :

    
    package app; 
    class demo
    {
    void clear()
    {
    System.out.println("clear method");
    }
    }

    class demo can be accessed anywhere in same package.