Python class inheritance 繼承

繼承重用已存在的程式碼,來降低程式的複雜度並提升維護性

superclass

subclass

繼承做兩件事

  1. class dog(Animal):繼承superclass Animal
  2. Animal.__init__(self):呼叫superclass父類別的建構子

改寫父類別Animal內的方法,與父類別方法名稱一樣,就會改寫Animal內的方法或擴增Animal已有的whoamI或沒有的方法bark

Like what you read? Give Steven Wang a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.