Recently I saw in somebody's code that he implements his final class variable fields inside an interface ex:
public interface commentSchema{
static final String DB_TABLE_NAME = "comment";
...
}
& he had implemented a class which does need these variables something like this:
public class DbComment implements commentSchema {
// use the DB_TABLE_NAME value here ...
...
}
as you know If someone make an instance of DbComment class because of inheritance aspect, he's gonna be able to access the DB_TABLE_NAME which is not proper because we want to use those values only inside DbComment methods.
now I have several questions:
1) is this implementation proper & ok ?
2) if It's not, how we have to declare these variables outside of DbComment class & make this class be the only class who does see these values. (we don't want to use abstract class coz a class can only extends one other class in java)
3) why we do need to use static for values & methods which exist inside an interface ? (when we implements certain interface for a specific class why do we need to make it static to be seen everywhere?)
4) is there any specification that exactly determine kinds of different declarations for java methods, classes, enums, etc ?