Excuse me, is I am new to Java and want to do an attribute (final)and static.

The problem is that first I need to instantiate and then, using a method to give its final value.

I need something this:

public static final int MyConstant;

public void createConstant(int pValue){
        MyConstant  = pValue;
    }

appreciate your help

A "final" variable can only be defined once, and when it is static it needs to be defined at the first reference to the Class. Which means that you won't be able to use a method to set the value of a static final variable. You could use a static block (which gets executed at class load time), but that's not quite the same thing. So, if it is going to be set by a method the variable can be static but it cannot be final, or it can be final (if the method is called by the constructor of the class), but it cannot be static.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.