Scroll to top

Non Access Modifiers in Java

Access modifiers provide a mechanism for Access Control and different access modifiers can be used to achieve different accessibility. But Non-Access Modifiers have nothing to do with accessibility. But it is used to determine specific characteristics of class/variable/methods etc.

Below are the 7 Non Access Modifiers available in Java.

  • Final
  • Abstract
  • Static
  • Strictfp
  • Native
  • Synchronized
  • Transient

Final Non Access Modifiers

Keyword

final

Applicability:

  1. Class
  2. Method
  3. Instance Variable
  4. Local Variable
  5. Method arguments

Final Class :

A class, when set to final, cannot be extended by any other class.

Example: A String Class in java.lang package

Final Method :

A method, when set to final, cannot be overridden by any subclass.

Final Variable :

When a variable is set to final, its value cannot be changed. The final variables are like constants.

Example : public static final int i = 10;


Abstract Non-Access Modifier

Keyword:

  • abstract

Applicability:

  1. Class
  2. Method

Abstract Class:

An Abstract class can have abstract methods. If a class has an abstract method, the class becomes an abstract class. A class can also be an abstract class without having any abstract methods in it.

Abstract Method :

Abstract methods are those methods that do not have a body but only a signature.

Example : public abstract void method();

Synchronized Non-Access Modifier

keyword

synchronized

Applicability

  1. Method

Synchronized Method

Synchronized methods can be accessed by only one thread at a time.

Native Non Access Modifier

Applicability

  1. Method

Native Method

Native methods indicate that the method is implemented on a platform-dependent code.

Strictfp Non-Access Modifier

Applicability

  1. Class
  2. Method

Strictfp Class / Method

Strictfp non-access modifier forces floating-point or floating-point operation to adhere to IEEE 754 standard.

Note*: Strictfp non-access modifier cannot be applied on a variable.

Cheatsheet

  • Non Access Modifiers available in Java are Static, final, abstract, synchronized & Volatile
  • Static keyword can be applied to Variables & Methods.
  • Static Variables are those variables that are not associated with any instance but are associated with the class, which means all instances will access the same single copy of the variable.
  • Local variables can not be declared as static.
  • Static keyword can also be applied to Methods. They will work for all the instances and they will not be dependent on instance creation.
  • A final modifier can be applied to methods and variables.
  • Final is the only modifier that will be available to the local variable.
  • Once declared as the final, the value of the variable can not be changed.
  • A final variable doesn’t get default value as opposed to instance variable coz value can’t be changed once assigned.
  • A final method cannot be overridden.
Author avatar
JBT
https://javabeginnerstutorial.com/

32 comments

  1. mobil porno

    Good web site you’ve got here.. It’s difficult to find excellent
    writing like yours these days. I truly appreciate individuals like you!
    Take care!!

  2. Balan

    You have listed Transient as one non access modified; but not explained it. Pl do the same.

  3. Sunil

    Nice website dude. Simple and awesome. One suggestion, think you missed to provide explanation about Transient.

  4. sandhya

    Good job man! Is it possible for you to give some real time example?

  5. Suma

    Hi,
    I am new to Java. Could you please provide more programming details on Abstract Class/Method.
    I would like to practise more on this.

    Thanks!!!

  6. Rajeeev

    seriously, y you doesn’t write applicable to interface ?

  7. Anonymous

    very informative

  8. ratna

    good explanations…Thank you gautam

  9. pranit

    Well explained and understanding post!
    All java beginner should go through this concept here, its very useful to know about java non access modifiers in java. Will be looking forward to know about java access modifiers with examples. Thanks for sharing!

  10. priya

    Good web site i am searching for this only .. It’s difficult to find excellent
    writing like yours . I truly appreciate individuals like you! Your site content are very easy to understand.

Post a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.