Ejemplo 1: constantes en Java
//A constant is a variable whose value won't change after it's been defined.
private static final int OUR_CONSTANT = 1;
//We make our constants static and final and give them an appropriate type,
//whether that's a Java primitive, a class, or an enum.
//The name should be all capital letters with the words separated by underscores,
//sometimes known as screaming snake case.
Ejemplo 2: declaración de java constante
final double Pi = 3.1415926536;
Ejemplo 3: crear una clase constante en java
public final class MyValues {
public static final String VALUE1 = "foo";
public static final String VALUE2 = "bar";
}
Ejemplo 4: que son las constantes y como crear constantes en java
Constants are fixed values whose values cannot be changed during
the execution of program. We create constants in java using final keyword.
Ex : final int number = 10;
final String str = ”I love Java”;
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)