Calling super() in Constructors

Part of: Inheritance

Constructors Are Not Inherited Unlike methods, constructors are not inherited . Each class must define how its own objects are built. But a subclass object still contains the superclass's fields, so those fields must be initialized too. That is the job of super(). The super() Call super(...) invokes a constructor of the superclass . It must be the first statement in the subclass constructor. When you create a Dog, Java first runs the Animal constructor (via super(name)) to set up the inherited name field, then finishes the Dog-specific setup. When super() Is Implicit If you do not write super(...), Java automatically inserts a call to the superclass's no-argument constructor super(). This means: - If the superclass has a no-arg constructor, you can omit super() safely. - If the superclass has only constructors that take arguments, you must call super(...) explicitly, or the code will not compile. Order of Construction Construction flows from the top of the hierarchy down: - Superclass constructor runs first. - Then the subclass constructor body runs. This guarantees inherited fields are ready before the subclass touches them. In the challenge you will build a Student that extends P

Challenge: Build a Student