Final is used to apply restrictions on class, method, and variable.
The final class can't be inherited, final method can't be overridden,
and final variable value can't be changed. Final is a keyword
First of all, final is a non-access modifier applicable only to
a variable, a method or a class
When a variable is declared with final keyword, its value can’t be modified,
essentially, a constant. This also means that you must initialize a
final variable. If the final variable is a reference, this means that
the variable cannot be re-bound to reference another object, but internal
state of the object pointed by that reference variable can be changed
i.e. you can add or remove elements from final array or final collection.
It is good practice to represent final variables in all uppercase, using
underscore to separate words.
class Main {
public static void main(String[] args) {
// create a final variable
final int AGE = 32;
// try to change the final variable
AGE = 45;
System.out.println("Age: " + AGE);
}
}
public static final String Name = "Jeff";
class scratch{
public static void main(String[] args){
final pi = 3.14;
}
}
Code Example |
---|
Java :: java :: operator |
Java :: testng with cucumber |
Java :: java search tree |
Java :: how to find last element in array java |
Java :: java define interface |
Java :: class in java |
Java :: how to use a switch statement in java |
Java :: set preference value android |
Java :: Jlabel icon |
Java :: java join array |
Java :: camel java |
Java :: constructeur java |
Java :: string formatting java |
Java :: xml button color not changing |
Java :: java reverse array |
Java :: android get id of view |
Java :: polimorfismo java ejemplo |
Java :: what are the chances that i pass this coming up test |
Java :: exitonclose swing |
Sql :: conda install sqlalchemy |
Sql :: brew restart mysql |
Sql :: how to truncate table with foreign key constraint |
Sql :: mysql change user password |
Sql :: return names of columns in table sql |
Sql :: sql now - 1 day |
Sql :: oracle columns table |
Sql :: mysql get first x characters |
Sql :: oracle select first 10 rows |
Sql :: psql filed name alter |
Sql :: crontab every month |