Super keyword behavior
📖 Scenario: Imagine you are creating a simple system to manage vehicles. You want to reuse some code from a basic vehicle class in a more specific car class. This helps avoid repeating code and keeps things organized.
🎯 Goal: You will build two classes: Vehicle and Car. The Car class will use the super keyword to call the constructor and methods of the Vehicle class. This shows how super helps reuse and extend code.
📋 What You'll Learn
Create a class called
Vehicle with a constructor that takes a make string and a method describe() that returns a description string.Create a class called
Car that extends Vehicle and has an additional property model.Use
super in the Car constructor to call the Vehicle constructor.Override the
describe() method in Car and use super.describe() inside it.Create an instance of
Car and print the result of its describe() method.💡 Why This Matters
🌍 Real World
Using <code>super</code> is common when building software with related objects, like vehicles, employees, or products, to avoid repeating code.
💼 Career
Understanding <code>super</code> and class inheritance is essential for many programming jobs, especially in frontend and backend development using TypeScript or JavaScript.
Progress0 / 4 steps