Jim Hoglund wrote:Please forgive a greenhorn question, but what OOP principle is being violated?
Jim...
None.
But you will get unpredictable side effects and strange errors that will be difficult to track/resolve.
Try to run this example:
Result is:
This is because of a way
java initialises objects - super class is initialized first before it's subclasses.
In the superclass constructor you call overridden method defined in the subclass,
this method refers to members of the subclass that are not initialized yet ... and this cause errors.
In the above example x=0 and y=null even than x is declared as 10 and y should be initialized to 20.
Remember that some time in the future your class could be used/extended by someone other
who will get strange errors that will confuse him.