static and final keywords in Java: Use of final to stop method overriding and inheritance

In Java, static keyword is used to define a member of a class, it could be a method or a variable without having any connection with the object of the class or without any reference to any instance.  By default a static variable is a global variable. However, you have to make sure that static member should call only other static methods and it could access only static data. Keywords like this and super can’t be used with static members. main is always as static because it is created before creation of any object.

For Example:

To define a variable as static:

static int x;

To define a method as static:

static void met(int y) {


To define main as static:

public static void main(String args[ ]) {


final keyword: final keyword is used to prevent a variable from modification of any kind. It is like you are informing that this variable is a constant. Usually, uppercase names are used for final variables. Apart from variables, a method can also be declared as final.

For Example:

final int FILE_NEW = 1;

Use of final to stop method overriding and inheritance in Java:

Inheritance is a powerful concept of Java. But in some occasions you need to control it. Final keyword is used to stop method overriding and inheritance.

To stop method overriding and inheritance, simply declare a method as final.

class Myclass {

final void met() {

System.out.println(“Final method. Can’t be overridden and no inheritance is possible.”);



Leave a Reply