-4

We have the next source of a Java class and some possibilities to secure its variables:

public class Foo {
    public static String ALPHA = "alpha";
    protected String beta = "beta";
    private final String delta; 
    public Foo(String d) {
        delta = ALPHA + d;
    }
    public String Foo() {
        return beta
    }
}

Which change make Foo more secure and why? We see here a question related to visibility modifiers and the convenience of using constants or variables.

A. protected final String beta = "beta"; 
B. private String delta; 
C. public static final String ALPHA = "alpha"; 
D. public String beta = "beta";
1
  • Define "secure".
    – luk2302
    Commented Jul 23, 2022 at 16:36

1 Answer 1

2

None of these will matter at all to security. This is a variable in your app, changing any of them will only be able to affect whether other parts of your app can read it or not. If your app itself can't be trusted, you have far bigger, unsolvable by technology problems.

Now if you're asking which is better for maintainability and keeping a clean API to the rest of your system- we have no idea because we don't know how your class will be used, and its way to generic to even guess what "alpha", "beta" or "delta" will do. I can tell you this won't compile, because you can't assign a new value to a final variable, which you do with delta.

Not the answer you're looking for? Browse other questions tagged or ask your own question.