将共性的内容放在父类中,子类只需要关注自己特有的内容
python中所有的内容都是对象,所有的对象都直接或间接继承了object

说明:
·虽然子类没有定义__init__方法,但是父类有,所以在子类继承父类的时候这个方法就被继承了,所以只要创建Bosi的对象,就默认执行了那个继承过来的__init__方法
总结
·子类在继承的时候,在定义类时,小括号()中为父类的名字
·父类的属性、方法,会被继承给子类




说明
·python中是可以多继承的,在java中叫接口
·父类中的方法、属性,子类会继承
网友评论