Change material on part of object with other overlapping object
You can create 2 overlapping cubes. Create somewhere a third cube that will be the boolean object and make it invisible in render. Give your 2 first cubes 2 different colors, give them both a Boolean modifier with the third cube as Object. For the orange cube, choose the Difference option, for the blue one, choose Intersect.