posted 19 years ago
I'm not sure is you're asking why things were done the way they were in the languauge or if you're just asking how things work...so this may not be helpful.
With the final instance variable in the class, the rule is that you have to assign a value to the variable in every constructor if you don't define it when the variable is declared. In your example, the (invisible) default constructor doesn't do this, so you get an error. The simple solution here would be:
or
As for the interface question, the only type of variables allowed in an interface are "constants" (static finals). As you say, there are no constructors, so you must init any such variables when you declare them:
Co-Author of <a href="http://www.oreilly.com/catalog/jswing2" target="_blank" rel="nofollow">Java Swing</a><br />Co-Creator of <a href="http://www.sun.com/training/catalog/courses/CX-310-055.xml" target="_blank" rel="nofollow">SCJP 5.0</a> and <a href="http://www.sun.com/training/certification/java/associate_beta.xml" target="_blank" rel="nofollow">SCJA</a> exams