Platinum Solutions Corporate Website


The answer you entered to the math problem is incorrect.
Richard Vanhook Wed, 1969-12-31 20:00

Craig, thanks for the feedback and I'm glad to see you're reading the blog!  That's an excellent point you noted concerning the byte code and the initialization occurring during the constructor - which is something I didn't realize and until now, have ever ran into any problems because of it.  Just to verify what you stated about the constructor is correct, I decompiled the Child class using cavaj and got the following (and as you can see, you were right on the mark):


class Child extends Parent
{

    private String varA;

    public Child()
    {
        varA = null;
    }

    public String getVarAValue()
    {
        return varA;
    }

    protected void setVarAValue()
    {
        varA = "a value";
    }
}


One clarification however concerning my statements: I was not trying to say that I believed this behavior was a bug in the Java language and that it violated any Java specs.  My point (to borrow Matt's phrasing) was its not intuitive behavior - which is inconsistent with the mostly intuitive Java language.  I'm not saying you can't write confusing Java code because you can; however, generally speaking, Java is more intuitive than other languages (or maybe I'm just biased because it's the language I like the most?).

Mr. PMD (aka Matt Harrah), very good point on the class design and I will definitely look into re-orging the method calls - there shouldn't be functionality affected as all that's really needed is an extra method in the Parent class like initialize().

Thanks for the feedback!

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2.
The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options