With sharing & Without sharing keywords

With sharing Keyword

This keyword enforces sharing rules that apply to the current user. If absent, code is run under default system context.

Example

public with sharing class MysharingClass {
    // Code will enforce current user's
    // sharing rules
}

Without sharing keyword

Ensures that the sharing rules of the current user are not enforced.

Example

public without sharing class noSharing {
    // Code won't enforce current user's
    // sharing rules
}