0
0
Javaprogramming~10 mins

Super keyword in Java - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Super keyword
Create Subclass Object
Call Subclass Constructor
Inside Subclass Constructor
Use super() to call Parent Constructor
Parent Constructor runs
Return to Subclass Constructor
Complete Subclass Constructor
Object Ready
Shows how creating a subclass object calls the subclass constructor, which uses super() to run the parent constructor first, then finishes.
Execution Sample
Java
class Parent {
  Parent() { System.out.println("Parent constructor"); }
}
class Child extends Parent {
  Child() { super(); System.out.println("Child constructor"); }
}
new Child();
Creates a Child object that calls Parent constructor first using super(), then runs Child constructor.
Execution Table
StepActionOutputNotes
1Create Child objectStart creating Child instance
2Call Child constructorChild() starts
3Call super() inside Child constructorParent constructorParent() runs first
4Return to Child constructorChild constructorChild() continues
5Child constructor endsObject creation complete
💡 Child object fully created after Parent and Child constructors run
Variable Tracker
VariableStartAfter Step 3After Step 5
this (Child object)nullpartially constructed (Parent part done)fully constructed
Key Moments - 3 Insights
Why does the Parent constructor run before the Child constructor finishes?
Because super() in the Child constructor calls the Parent constructor first, as shown in step 3 of the execution_table.
What happens if we omit super() in the Child constructor?
Java inserts super() automatically if no other constructor call is present, so Parent constructor still runs first.
Can super() be called after some code in the Child constructor?
No, super() must be the first statement in the Child constructor, or the code will not compile.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is printed at step 3?
ANo output
BChild constructor
CParent constructor
DError
💡 Hint
Check the Output column for step 3 in the execution_table
At which step does the Child constructor print its message?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look at the Output and Notes columns for step 4 in the execution_table
If super() was missing in the Child constructor, what would happen?
AParent constructor would not run
BParent constructor runs automatically
CCompilation error
DChild constructor runs twice
💡 Hint
Recall the key_moments about implicit super() call
Concept Snapshot
Super keyword in Java:
- Used in subclass to call parent class constructor or methods
- super() must be first line in subclass constructor
- Ensures parent class is initialized before subclass
- Helps access overridden methods or hidden variables
- If omitted, Java inserts super() automatically in constructor
Full Transcript
This visual trace shows how the super keyword works in Java. When creating a Child object, the Child constructor runs. Inside it, super() calls the Parent constructor first, printing "Parent constructor". Then control returns to the Child constructor, which prints "Child constructor". This order ensures the parent part of the object is set up before the child part. The variable tracker shows the Child object is partially constructed after the Parent constructor runs, and fully constructed at the end. Key points include that super() must be the first statement in the constructor, and if omitted, Java adds it automatically. The quizzes test understanding of the print order and behavior if super() is missing.