Options
Java: Declaring a variable in superclass, then changing it in subclass
Code such as this calls an error on the subclass line that says "cannot assign a value to a final variable"
So if I'm initializing a variable in the superclass, how do I then set it in the subclass - or am I doing something fundamentally wrong? Should I not be declaring a such variable in the superclass?
Thanks!
public interface Sample { public String firstName = ""; } public class Undertone implements Sample{ public void setFirstName(){ firstName = "DEFAULT"; // Error for this line } }
So if I'm initializing a variable in the superclass, how do I then set it in the subclass - or am I doing something fundamentally wrong? Should I not be declaring a such variable in the superclass?
Thanks!