- Hands-On Penetration Testing with Python
- Furqan Khan
- 133字
- 2021-07-02 14:14:00
Polymorphism with functions
Let's think about two classes, Ferrari and McLaren. Let's assume that both have a Speed() method that returns the top speed of the cars. Let's think about how can we use function polymorphism in this scenario. Let's create a file called Poly_functions.py:

We can see that we have two classes, Ferrari and McLaren. Both have a common speed method that prints the speed of the two cars. One approach would be to create instances of both the classes and invoke the print speed method with each instance. Another approach could be to create a common method that takes the instance of the classes and that invokes the speed method on the instances it receives. This is the polymorphic printSpeed(carType) function that we defined at line 10.
推薦閱讀
- Learning C# by Developing Games with Unity 2020
- LabVIEW Graphical Programming Cookbook
- Boost C++ Application Development Cookbook(Second Edition)
- Ext JS Data-driven Application Design
- INSTANT Weka How-to
- Gradle for Android
- 單片機C語言程序設計實訓100例
- 微信小程序全棧開發技術與實戰(微課版)
- Learning Unreal Engine Android Game Development
- Vue.js 2 Web Development Projects
- .NET 4.5 Parallel Extensions Cookbook
- Android系統下Java編程詳解
- 人人都能開發RPA機器人:UiPath從入門到實戰
- XML程序設計(第二版)
- Python應用開發技術