Tuesday 29 November 2016

Chapter 4.1: Non Access Modifiers in Java-Final Non Access Modifiers, Abstract Non Access Modifier, Synchronized Non Access Modifier, Native Non Access Modifier, Strictfp Non Access Modifier



Here in this article you will learn about Non Access Modifiers in Java. There are different non access modifiers available in Java.
  • Final
  • Abstract
  • Static
  • Strictfp
  • Native
  • Synchronized
  • Transient

Final Non Access Modifiers:

Applicable to :

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

Final Class :

Once Final non access modifier is applied to Class. Class can not be Extended by any other class.

Example: String Class in java.util package


Final Method :

Once Final non access modifier is applied to Method. That method can not be Overriden in subclass.
Example :

Final Variable :

Once Final non access modifier is applied to Variable. That variable’s value can not be Changed once assigned. Final variable are like constants.
Example : public static final int i = 10;

Abstract Non Access Modifier

Keyword: abstract

Applied to:

  1. Class
  2. Method

Abstract Class:

Abstract class can have(Not compulsary) abstract method. A class can also be an abstract class without having any abstract method in it. But once a class have an abstract method class becomes abstract class.

Abstract Method :

Abstract method are those methods which doesn’t have a body but only specification.
Example : public void method();



Synchronized Non Access Modifier

Applied to

  1. Method(Only)

Synchronized Method

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

Native Non Access Modifier

Applied to

  1. Method(Only)

Native Method

Naive method indicates that a method is implemented in platform dependent code.

Strictfp Non Access Modifier

Applied to

  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 to variable.

No comments:

Post a Comment