Challenge #1: Override a Method using the Super Keyword

Can you override a method in a derived class with the help of super keyword? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.

Problem Statement

When a method in a derived class overrides a method in a base class, it is still possible to call the overridden method using the super keyword.

If you write super.method(), it will call the method that was defined in the superclass.

You are given a partially completed code in the editor. The class Shape is the base class of the XShape class. You have to modify the getName() method of the derived class, i.e XShape, so that the code returns the following:

Input

Derived Class Name

Output

Base Class Name, Derived Class Name

Sample Input

         Shape circle = new XShape("Circle");

Sample Output

         "Shape, Circle"

The partially completed code in the editor (in the getName() function) does not return the correct output so you can modify it as well to make it correct.

Get hands-on with 1400+ tech skills courses.