Your question is Java Inheritance and Overriding. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Align Technology's treatment-planning software builds each clear-aligner treatment plan out of a chain of TreatmentStep objects, where a specialized step like an AlignerAdjustment can override how it logs itself. A QA engineer is reviewing the class below during a code walkthrough.
public class TreatmentStep {
protected int stepNumber;
public TreatmentStep() {
stepNumber = 1;
logStep();
}
public void logStep() {
System.out.println("Base step: " + stepNumber);
}
public static void main(String[] args) {
TreatmentStep step = new AlignerAdjustment();
step.logStep();
}
}
class AlignerAdjustment extends TreatmentStep {
private int adjustmentLevel = 5;
@Override
public void logStep() {
System.out.println("Adjustment level: " + adjustmentLevel);
}
}
What is printed when main runs, in order, and why? Walk through the construction and method-dispatch sequence line by line to justify your answer.