Yes, you may change the function's mutability to a more strict one.
See this quote from the solidity docs
The overriding function may only change the visibility of the overridden function from external to public. The mutability may be changed to a more strict one following the order: nonpayable can be overridden by view and pure. view can be overridden by pure. payable is an exception and cannot be changed to any other mutability.
Now check out this example, also provided in the documentation:
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Base
{
function foo() virtual external view {}
}
contract Middle is Base {}
contract Inherited is Middle
{
function foo() override public pure {}
}
This contract compiles completely fine since the view
function was made into a more strict pure
function.
Now if we take the same example, but try to take away the view
keyword, we get this error on compile:
TypeError: Overriding function changes state mutability from "view" to "nonpayable".
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Base
{
function foo() virtual external view {}
}
contract Middle is Base {}
contract Inherited is Middle
{
function foo() override public {}
}