About the protection of methods and properties inherited from base classes:
--class pig:public Animal {...}
C + + Not only allows you to enforce access control over the methods and properties defined in the class, but also allows you to control which methods and properties in the base class can be accessed by subclasses.
Public
-is telling the compiler that there is no change in the access level of inherited methods and properties, that public can still be accessed by all code, that protected can only be accessed by subclasses of the base class, and private only by the base class itself.
Protected
-Change the access level of the base class to protected, and if it is public, this will make it impossible for code outside the subclass to access public in the base class through subclasses.
Private
-is to tell the compiler that each member inherited from the base class is treated as private, which means that only this subclass can use the elements it inherits from the base class.
Note: Generally only use public!
Public,protected,privat differences