Back to Freecodecamp

Step 10

curriculum/challenges/english/blocks/learn-interfaces-by-building-an-equation-solver/66759e32b88fb5459b1e0234.md

latest1.1 KB
Original Source

--description--

The __init_subclass__ method is called whenever the class that defines it is subclassed and it enables to customize the child classes. The method takes a parameter named by convention cls (standing for "class"), which represents the new child class.

Define an __init_subclass__ method in your Equation class and give it a cls parameter.

--hints--

You should define an __init_subclass__ method with a cls parameter in your Equation class.

js
({ test: () => assert(runPython(`_Node(_code).find_class("Equation").find_function("__init_subclass__").has_args("cls")`)) })

--seed--

--seed-contents--

py
from abc import ABC, abstractmethod


class Equation(ABC):
    degree: int
    
    def __init__(self):
        pass
--fcc-editable-region--
    
--fcc-editable-region--
    @abstractmethod
    def solve(self):
        pass
        
    @abstractmethod
    def analyze(self):
        pass


class LinearEquation(Equation):
    def solve(self):
        pass

    def analyze(self):
        pass


lin_eq = LinearEquation()