The sharing documentation Using the with sharing, without sharing, and inherited sharing Keywords says:
- The sharing setting of the class where the method is defined is applied, not of the class where the method is called. For example, if a method is defined in a class declared with
with sharingis called by a class declared withwithout sharing, the method executes with sharing rules enforced. - Both inner classes and outer classes can be declared as
with sharing. The sharing setting applies to all code contained in the class, including initialization code, constructors, and methods. - Inner classes do not inherit the sharing setting from their container class.
I have an awkward case where I have inherited sharing inner classes called from with sharing and without sharing inner classes of a different outer class. See a Clean way to vary sharing at runtime in Apex? for that code. The aim is for the with sharing and without sharing to be respected and by my reading of the documentation it should be based on the last bullet point above.
Do you agree? Right now I have some confusing test results...
(A related question is Sharing rules and Inner classes.)
PS
I assume that a "Default Internal Access" setting of "Private" is ignored in Apex without sharing code but at present my test does not support that assumption.