Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!

Java Programming

Java – Use of Final Keyword in Java

Use of Final Keyword in Java

If you declared Java variable is final, then that variable cannot re-declared that declaration for the single time.

Means that variable can be initialized only for a single time.  If Java classes are declared final, then those Java classes cannot be further extended.

It means you cannot inherit the data from the superclass. The final keyword is used for the following purposes in Java.

  1. Preventing a class from being inherited by another class.
  2. Declaring a constant variable
  3. Preventing a method from being overridden.

the following syntax is used to declare the final class, 

public final class XYZ{
Statements1;
Statements2;
Statements3;
.
.
}

the following syntax is used to declare the final variable,

public final class XYZ{
public final int PI=3.14;
public final float I=2.14F;
.
.
}

the following syntax is used to declare the final method,

public final class XYZ{
public final void display(){
.........
.........
}
.
.
}
Avatar

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like

introduction to java programming
Java Programming

Java – Introduction, Features, Versions & History

  • December 20, 2020
Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented. Java inherits its object-oriented features from C++. Java
basic terms of java programming
Java Programming

Java – Basic Terms of Java Programming

  • December 20, 2020
A Java program, similar to programs in other programming languages, It also uses the literals, variables, tokens, data types, etc.