In a closed interval [a, b] the extreme value can occur at a point where the derivative is 0 or undefined AND within [a, b] OR the extreme value can occur at an endpoint (or endpoints).
Can you draw three diagrams for f(x) such that on the closed interval say [5, 10]
a) the max is not at an endpoint
b) the max is at x=5
c) the max is at x=10