Access and Non Access Modifiers in Java

Course Curriculum

Access and Non Access Modifiers in Java

Access and Non Access Modifiers in Java

Access Modifiers : Java’s access modifiers are public, private, and protected. Java also defines a default access level (called package-private).
How they work?

public: When a member of a class is modified by public, then that member can be accessed by any other code.
private: When a member of a class is specified as private, then that member can only be accessed by other members of its class.
Now you can understand why main( ) has always been preceded by the public modifier. It is called by code that is outside the program—that is, by the Java run-time system. When no access modifier is used, then by default the member of a class is public within its own package, but cannot be accessed outside of its package. protected applies only when inheritance is involved.

Non-access modifiers : In java, we have 7 non-access modifiers. They are used with classes, methods, variables, constructors etc to provide information about their behavior to JVM.They are

  • static
  • final
  • abstract
  • synchronized
  • transient
  • volatile
  • native
Association, Composition and Aggregation in Java (Prev Lesson)
(Next Lesson) Access Modifiers in Java