You are on page 1of 3

02/02/2022, 21:47 Challenge 1: Override a Method Using the Super Function - Learn Object-Oriented Programming in Python

(/learn)

Challenge 1: Override a Method Using the


Super Function
In this challenge, you will override a method using super().

We'll cover the following

• Problem statement
• Sample input
• Sample output

• Coding exercise

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() function.

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. Modify the code so
that it returns the following:

Sample input#
circle = XShape("Circle");

circle.getName()

Sample output#
https://www.educative.io/courses/learn-object-oriented-programming-in-python/N0AOYxLBpBp 1/3
02/02/2022, 21:47 Challenge 1: Override a Method Using the Super Function - Learn Object-Oriented Programming in Python

"Shape, Circle"

The Shape class is already prepended in the code and it has one property,
sname and one method, getName() . getName() returns sname .

Shape

sname="Shape"

getName()

XShape

xsname

getName()

Parent and child class structures

Show hint

Coding exercise#
First, take a close look, and then, design a step-by-step algorithm before
trying the implementation. This problem is designed for your practice, so
initially, try to solve it on your own. If you get stuck, you can always refer
to the solution provided in the solution review.

Good luck!

https://www.educative.io/courses/learn-object-oriented-programming-in-python/N0AOYxLBpBp 2/3
02/02/2022, 21:47 Challenge 1: Override a Method Using the Super Function - Learn Object-Oriented Programming in Python

class XShape(Shape):

# initializer

def __init__(self, name):

self.xsname = name

def getName(self): # overriden method

return (self.xsname)

The solution will be explained in the next lesson.

Back Next

Quick Quiz! Solution Review 1: Override a Method …

Mark as Completed

Report an Issue

https://www.educative.io/courses/learn-object-oriented-programming-in-python/N0AOYxLBpBp 3/3

You might also like