[Day15]-类别2

  • 类别继承
  1. 定义:可以继承父类别所有的公有方法与属性,在子类别就不用重新设计
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644PuNhQnzGis.png
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644aQnWp38WBR.png
  2. 基於保护原则,外部是不能直接取得内部的私有属性,但是可以使用return来取得私有属性
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644kI4YQ0pVCp.png
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644Rm7kx6Ytrw.png
  3. 衍生类别引用基底类别的方法,需要使用super()
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644anVldYeJl3.png
    https://ithelp.ithome.com.tw/upload/images/20210927/201406445Bp5fvbsfJ.png
  4. 三代同堂,子类别要取得父类别很容易,但要取得祖父类别就没有这麽简单,方法只有在父类别跟子类别里的__init__()里增加super().init()
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644xevkG493wE.png
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644NhjG6qlLmN.png
  • 多重继承
  1. 基本格式如下:
    class 类别(父类别1, 父类别2,……父类别n)
    程序码
    https://ithelp.ithome.com.tw/upload/images/20210927/201406442nbf4cOV0I.png
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644IijU4lYyES.png
  2. Super()应用在多重继承
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644ygERu41rcK.png
    https://ithelp.ithome.com.tw/upload/images/20210927/20140644aQ28TXvZtP.png

<<:  【贺】ACL AI人工智慧资料分析软件原厂加入勤奋Diligent集团,成为全球GRC(治理、风险管理与法规遵循)领先者,为全球25,00家组织超过100万个各产业菁英持续提供全方位优质服务

>>:  Day - 12 集合

Flutter API Get using Bloc state management and http plugin

Flutter API Get using Bloc state management and ht...

Day 30 - 从大学肄业,联成电脑,到 Microsoft MVP 得奖,从零开始的软件工程师,职场与薪水

薪水 接下来会多聊一些关於转职相关的东西 首先是薪水,以下是月薪 25k-33k 40k-75k 5...

Day17 [实作] RTCPeerConnection: 本机端模拟 P2P 的过程

上一篇我们通过简单的例子了解 Offer / Answer 的机制,今天我们要加上视讯: Bob 通...

Day28:28 - 後端&前端 - 按赞收藏

Moni,我是Charlie! 在Day27当中我们完成了recaptcha验证,而今天我们将实作按...

Day-13 Ruby简单的程序考题!

有些公司会有上机的程序考题,相信初心者会怕怕(我个人是会啦),但从简单的题目开始学习吧! 把阵列 ...