Access Modifiers in Java

ACCESS MODIFIER WITHIN CLASS WITHIN PACKAGE PACKAGE BY INHERITANCE PACKAGE BY ASSOCIATION
Private Yes No No No
Default Yes Yes No No
Protected Yes Yes Yes No
Public Yes Yes Yes Yes
  • The access modifiers in java specifies accessibility (scope) of a data member, method, constructor or class.
  • There are two types of modifiers in java access modifiers and non-access modifiers.
  • There are many non-access modifiers such as static, abstract, synchronized, native, volatile, transient etc.
  • There are four types of access modifiers in java
    1. The private access modifier is accessible only within class.
    2. If we do not use any modifier, it is treated as default access modifiers bydefault.
    3. The protected access modifier can be applied on the data member, method and constructor, class.
    4. The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.
  • Keywords - Special tokens which have reserved use in the language

    abstract double int super
    assert else interface switch
    boolean enum long synchronized
    break extends native this
    byte final new throw
    case finally package throws
    catch float private transient
    char for protected try
    class goto public void
    const if return volatile
    continue implements short while
    default import static
    do instanceof strictfp

    Identifiers

  • Identifiers are the names of variables, methods, classes, packages and interfaces.
  • Identifiers start with a letter, underscore(_), or dollar sign($).
  • Identifiers are case sensitive and have no maximum length.
  • In the HelloWorld program, HelloWorld , String , args , main and println are identifiers.
  • Example: userName, user_name, $change

  • | Copyright ©2016 | All Rights Reserved |
    | Design by Uves Khan |

    Free Web Hosting