- 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.
推薦閱讀
- 數據科學實戰手冊(R+Python)
- 數據結構簡明教程(第2版)微課版
- Visual Basic程序設計習題解答與上機指導
- Oracle BAM 11gR1 Handbook
- HTML5秘籍(第2版)
- 區塊鏈技術進階與實戰(第2版)
- Xcode 6 Essentials
- Illustrator CS6設計與應用任務教程
- Node.js從入門到精通
- Java EE 7 with GlassFish 4 Application Server
- INSTANT Apache ServiceMix How-to
- Learning C++ by Creating Games with UE4
- 軟技能2:軟件開發者職業生涯指南
- Scala實用指南
- 測試基地實訓指導