Modifiers are specific keywords present in Java using that we can make changes to the characteristics of a variable, method, or class and limit its scope. Java programming language has a rich set of Modifiers. Modifiers in Java are divided into two types
- Access Modifiers
- Non-Access modifiers
Non-access modifiers provide information about the characteristics of a class, method, or variable to the JVM. Seven types of Non-Access modifiers are present in Java. They are
- static
- final
- abstract
- synchronized
- volatile
- transient
- native
Read more about Non-Access Modifiers in Java. In this article, we are going to discuss the differences among Final, Static, and Abstract Non-Access Modifiers.
Final Non-Access Modifier
The final non-access modifier is applicable to classes, methods, and variables. If we declare a parent class method as final then we can’t override that method in the child class because its implementation is final and if a class is declared as final we can’t extend the functionality of that class i.e we can’t create a child class for that class i.e inheritance is not possible for final classes. Every method present inside the final class is always final y default but every variable present inside the final class need not be final. The main advantage of the final keyword is we can achieve security and we can provide a unique implementation. But the main disadvantage of the final keyword is we are missing key benefits of OOPs like Inheritance(Because of the final class), Polymorphism(Because of the final method) hence if there are no specific requirements then it is not recommended to use the final keyword.
Example 1:
Java
import java.io.*;
import java.util.*;
class P {
public void firstName()
{
System.out.println( "Mayank" );
}
public void surName()
{
System.out.println( "Trivedi" );
}
}
class C extends P {
public void surName()
{
System.out.println( "Sharma" );
}
public static void main(String[] args)
{
System.out.println( "GFG" );
}
}
|
Output:
GFG
Example 2:
Java
import java.io.*;
import java.util.*;
class P {
public void firstName()
{
System.out.println( "Mayank" );
}
public final void surName()
{
System.out.println( "Trivedi" );
}
}
class C extends P {
public void surName()
{
System.out.println( "Sharma" );
}
public static void main(String[] args)
{
System.out.println( "GFG" );
}
}
|
Output:

Static Non-Access Modifier
The static non-access modifier is applicable for methods and variables but not for classes. We can declare a top-level class with a static modifier but we can declare the inner class as static (such types of inner classes are known as static nested classes). In the case of instance variable for every object, a separate copy will be created but in the case of static variable, a single copy will be created at class level and shared by every object of that class.
Example:
Java
import java.io.*;
import java.util.*;
class GFG {
static int x = 10 ;
int y = 20 ;
public static void main(String[] args)
{
GFG t1 = new GFG();
t1.x = 888 ;
t1.y = 99 ;
GFG t2 = new GFG();
System.out.println(
"Value of Static variable x = " + t2.x + "\n"
+ "Value of Instance variable y = " + t2.y);
}
}
|
Output:

Abstract Non-Access Modifier
The abstract non-access modifier is applicable only for classes and methods but not for variables. If we declare any method as abstract then that method must have its implementation in the child class of the respective class because abstract methods never talk about implementation. If any modifier talks about implementation then it forms an illegal combination with an abstract modifier. In a similar way if for any java class if we are not allowed to create an object (because of partial implementation) then such type of class we have to declare with abstract modifier.
Example:
Java
import java.io.*;
import java.util.*;
abstract class Vehicle {
abstract public int getNumberOfWheel();
}
class Bus extends Vehicle {
public int getNumberOfWheel() { return 7 ; }
}
class Auto extends Vehicle {
public int getNumberOfWheel() { return 3 ; }
}
public class GFG {
public static void main(String[] args)
{
Bus b = new Bus();
Auto a = new Auto();
System.out.println( "Number of wheels in bus is"
+ " " + b.getNumberOfWheel());
System.out.println( "Number of wheels in Auto is"
+ " " + a.getNumberOfWheel());
}
}
|
Output:

Difference Table
Final Non-Access Modifier | Static Non-Access Modifier | Abstract Non-Access Modifier |
---|
This modifier is applicable to both outer and inner classes. | This modifier is not applicable to outer classes. | This modifier is applicable to both outer and inner classes. |
This modifier is not applicable to interfaces | This modifier is not applicable to interfaces. | This modifier is applicable to interfaces. |
This modifier is the only modifier that is applicable for local variables. | This modifier is not applicable for local variables. | This modifier is not applicable for local variables. |
Final method can’t be inherited. | Static methods can only access the static members of the class and can only be called by other static methods. | Abstract method can be inherited. |