014-006-008
super Call in Method Chain
Medium
Problem Description
super Call in method Chain
In this problem, you will create a program that uses the super keyword across a 3-level class hierarchy (Grandparent→Parent→Child) to chain parent method calls, reading each level's name from standard input and displaying messages in sequence.
Learning Objective: Understand method chaining with super in inheritance hierarchy
Overview
Read 3 names from standard input and create a program with 3-level class inheritance where each level calls methods via super, stacking processing.
Input
3 lines of strings (names corresponding to the Grandparent, Parent, and Child classes)
Specifications
- Grandparent class has a
namefield, a constructor (accepting a name), and greet() method (outputs "Hello from {name}") - Parent class extends Grandparent, constructor accepts 2 names, overrides greet() (calls super.greet() then outputs "Hello from {parentName}")
- Child class extends Parent, constructor accepts 3 names, overrides greet() (calls super.greet() then outputs "Hello from {childName}")
- Read 3 names from Scanner in Main and call greet() on a Child instance
Input/Output Example
Input:
Grandparent
Parent
Child
Output:
Hello from Grandparent
Hello from Parent
Hello from Child
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up