Skip to main content

Introduction to Modifiers

📊 Modifier Usage Table

ModifierTop Level ClassClass VariablesLocal VariablesClass BlocksLocal BlocksConstructorsMethods
privateNAANANANAAA
protectedNAANANANAAA
publicAANANANAAA
finalAAANANANAA
staticNAANAANANAA
abstractANANANANANAA
nativeNANANANANANAA
strictfpANANANANANAA
synchronizedNANANANAANAA
transientNAANANANANANA
volatileNAANANANANANA

📝 Legend:

  • A → Allowed
  • NA → Not Allowed

⚠️ Important Notes

🔹 1. Top-Level Class Modifiers

  • Allowed: public, abstract, final, strictfp
  • Not allowed: private, protected, static

🔹 2. Local Variables

  • Only modifier allowed: final

🔹 3. Constructors

  • Cannot use: static, final, abstract

🔹 4. Methods

  • Can use most modifiers like:
    • public, private, protected
    • static, final, abstract, synchronized, native, strictfp

🔹 5. Special Modifiers

  • transient → only for variables
  • volatile → only for variables

🔹 6. Order of Modifiers

public static final int x=10;

✔ Order can be anything, but convention matters


🧠 Quick Summary

  • int[]... → var-args of arrays
  • Var-args behaves like array internally
  • Modifiers define access + behavior
  • Not all modifiers are allowed everywhere