The other method accepts two parameters, a CoffeeSelection, and an int. The first one accepts one parameter of type CoffeeSelection. The BasicCoffeeMachine class implements two methods with the name brewCoffee. Let’s use the same CoffeeMachine project as we used in the previous posts of this series. This approach is called static binding or static polymorphism. We can also add new features to the child class other than those present in the parent class. Using inheritance, we can make a child class with all the parent class’s features and methods. This becomes possible because Python supports the feature of inheritance. That signature allows the compiler to identify which method to call and binds it to the method call. In Python, we can extend a class to create a new class from the existing one. In most cases, each of these overloaded methods provides a different but very similar functionality.ĭue to the different sets of parameters, each method has a different signature. This kind of overloading is not recommended because it makes the API difficult to understand For example, one method accepts a String and a Long and another one accepts a Long and a String.
0 Comments
Leave a Reply. |