Can we restrict record access from users who are on a higher level in the role hierarchy in salesforce,
through Apex or admin
In Setup > Sharing settings, you can uncheck the "Grant Access Using Hierarchies" checkbox against that object.
You can uncheck the 'Grant Access Using Hierarchies' in sharing settings, but the point to remember is the impact will be on the object level and not for any specific users.
If you want to control the access to some specific records for some specific users, check the OWD of that object and if it is private/public read only, you can control the access via sharing rules.
Yes, Disabling Grant access using hierarchies
checkbox will only possible on custom objects, not for standard objects in Salesforce.
And before Restriction Rules
arrives, Salesforce only having the functions to open the record access only like Role hierarchy/Sharing rules. Not for restriction.
So as already phil W mentioned in comment, You can use Restriction Rules which has helping to achieve your requirement.
Please let me know if it helps.