Options

Java: Declaring a variable in superclass, then changing it in subclass

westwardwestward Member Posts: 77 ■■□□□□□□□□
Code such as this calls an error on the subclass line that says "cannot assign a value to a final variable"
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!
Sign In or Register to comment.