DEV Community

Maria Boldyreva
Maria Boldyreva

Posted on

Introduction to Java: modifiers cheatsheet

Modifiers in Java still seem tricky to me, so I'll try to put it as short as possible.

Modifiers are words that alter the class / method / variable behavior. The two main types are access and non-access modifiers.

  1. Access modifiers alter visibility:

    • no modifier - the class is visible to its package
    • private - only to the class
    • public - to every class everywhere
    • protected - to the package and its subclasses
  2. Non-access modifiers alter other functionalities:

    • static - makes the declaration class specific, not instance specific. It allows to use the method without an actual instance
    • final - doesn't allow the reference to change
    • abstract - for a method, declares that the method should be overriden in subclasses, for a class, that it cannot be instantiated, only subclassed

Top comments (0)