1. All classes are inherited directly or indirectly with object.
2. The super () method can be used to access the methods of the parent class, and if the subclass has a method with the same name as the parent class, the subclass overrides the method of the parent class.
3. After the definition of a class-level member, all descendants share a class-level member
classContact (object):#class-Level member variablesContact_list = [] def __init__(self, name, email, telephone):#member variables at the object levelSelf.name =name Self.email=Email Self.telephone=telephone Contact.contact_list.append (self) contact_a= Contact ('Tom','[email protected]', 123456) Contact_b= Contact ('Lucy','[email protected]', 123457)Print('Contact :') forCinchcontact.contact_list:Print(c.name)classFriend (Contact): Friend_list= [] #overriding methods of the parent class def __init__(self, name, e-mail, telephone, age):#calling a method of the parent classSuper (Friend, self).__init__(name, email, telephone) self.age=Age Friend.friend_list.append (self) friend_a= Friend ('Jack','[email protected]', 123458, 22) Friend_b= Friend ('Jim','[email protected]', 123459, 23) #It's a little strange that the child class has quite the same contact_listPrint(contact.contact_list)Print(friend.contact_list)Print('Friends:') forFinchfriend.friend_list:Print(F.name, F.age)
013:class and objects > Simple inheritance