What’s the point of inheritance in Python?

前端 未结 11 2080
一向
一向 2020-12-12 10:11

Suppose you have the following situation

#include 

class Animal {
public:
    virtual void speak() = 0;
};

class Dog : public Animal {
             


        
11条回答
  •  时光说笑
    2020-12-12 11:10

    Inheritance in Python is more of a convenience than anything else. I find that it's best used to provide a class with "default behavior."

    Indeed, there is a significant community of Python devs who argue against using inheritance at all. Whatever you do, don't just don't overdo it. Having an overly complicated class hierarchy is a sure way to get labeled a "Java programmer", and you just can't have that. :-)

提交回复
热议问题