Super Keyword Behavior
📖 Scenario: Imagine you are creating a simple system to manage employees and managers in a company. Managers are employees but with extra responsibilities. You want to reuse the employee's greeting message and add a special note for managers.
🎯 Goal: Build a Ruby program that shows how the super keyword works by calling a method from a parent class inside a child class method.
📋 What You'll Learn
Create a class called
Employee with a method greet that returns the string "Hello from Employee".Create a class called
Manager that inherits from Employee.In
Manager, override the greet method to call super and add " and Manager here!" to the returned string.Print the result of calling
greet on an instance of Manager.💡 Why This Matters
🌍 Real World
Understanding how to reuse code from parent classes helps you write cleaner and more maintainable programs, especially when working with related objects like employees and managers.
💼 Career
Inheritance and the <code>super</code> keyword are fundamental concepts in object-oriented programming used in many software development jobs to build scalable and organized code.
Progress0 / 4 steps