Both inner classes and outer classes can be declared aswith sharing. The sharing setting applies to all code contained in the class, including initialization code, constructors, and methods.
Inner classes donotinherit the sharing setting from their container class.
The term “with sharing” is used in the Salesforce program for businesses to use to maintain and market their companies and their companies’ products. If this term is not used, then the sharing rules for this user can’t be used for a certain class. This term has to be used in order to allow access into an account for a class with the sharing rules.
Most things are accessed in the system context through the Apex code. It is important for the user to designate whether “with sharing” or “without sharing” should be used. In regard to “with sharing” keyword, the inner class does not inherit the sharing setting from the container class. This is because it must be set by the user.