[proofplan]
We prove the strong maximum principle (ii) first, then deduce the weak maximum principle (i) as a corollary. If $u$ attains its maximum $M$ at an interior point $x_0$, the [mean-value property](/theorems/31) forces $u \equiv M$ on every ball centred at $x_0$ contained in $U$. The set where $u = M$ is then both open (by the mean-value argument) and closed (by continuity), so [connectedness](/page/Connectedness) forces $u \equiv M$ throughout $U$.
[/proofplan]
[step:Show that an interior maximum forces local constancy via the mean-value property]
Let $M := \max_{x \in \overline{U}} u(x)$, and suppose $x_0 \in U$ satisfies $u(x_0) = M$. Set $r_0 := \operatorname{dist}(x_0, \partial U) > 0$. For any $0 < r < r_0$, the ball mean-value formula from the [Mean-Value Formulas](/theorems/31) gives:
\begin{align*}
M = u(x_0) = \frac{1}{\mathcal{L}^n(B(x_0,r))} \int_{B(x_0, r)} u(y) \, d\mathcal{L}^n(y).
\end{align*}
Since $u(y) \le M$ for all $y \in B(x_0, r)$:
\begin{align*}
M = \frac{1}{\mathcal{L}^n(B(x_0,r))} \int_{B(x_0, r)} u(y) \, d\mathcal{L}^n(y) \le \frac{1}{\mathcal{L}^n(B(x_0,r))} \int_{B(x_0, r)} M \, d\mathcal{L}^n(y) = M.
\end{align*}
Equality holds throughout, so $\int_{B(x_0,r)} (M - u(y)) \, d\mathcal{L}^n(y) = 0$. Since $M - u(y) \ge 0$ is continuous, this forces $u(y) = M$ for all $y \in B(x_0, r)$.
[guided]
Suppose $u$ attains its maximum value $M := \max_{\overline{U}} u$ at an interior point $x_0 \in U$. We want to show that $u$ must equal $M$ in an entire neighbourhood of $x_0$.
Set $r_0 := \operatorname{dist}(x_0, \partial U) > 0$, so $\overline{B(x_0, r)} \subseteq U$ for any $0 < r < r_0$. The [Mean-Value Formulas](/theorems/31) give:
\begin{align*}
M = u(x_0) = \frac{1}{\mathcal{L}^n(B(x_0,r))} \int_{B(x_0, r)} u(y) \, d\mathcal{L}^n(y).
\end{align*}
On the other hand, $u(y) \le M$ for every $y \in \overline{U}$, so the average is at most $M$:
\begin{align*}
\frac{1}{\mathcal{L}^n(B(x_0,r))} \int_{B(x_0, r)} u(y) \, d\mathcal{L}^n(y) \le M.
\end{align*}
Since the average equals $M$ and the integrand satisfies $u(y) \le M$ everywhere, the non-negative function $M - u$ has zero integral over $B(x_0, r)$:
\begin{align*}
\int_{B(x_0,r)} (M - u(y)) \, d\mathcal{L}^n(y) = 0.
\end{align*}
A non-negative continuous function with zero integral must vanish identically: if $M - u(y_0) > 0$ at some $y_0 \in B(x_0, r)$, then by continuity $M - u > 0$ on a neighbourhood of $y_0$, giving a strictly positive integral on that neighbourhood, a contradiction. Therefore $u(y) = M$ for all $y \in B(x_0, r)$.
[/guided]
[/step]
[step:Propagate constancy to all of $U$ via connectedness]
Define $E := \{ x \in U : u(x) = M \}$. The previous step shows that $E$ is open in $U$: if $x \in E$, then $u \equiv M$ on $B(x, \operatorname{dist}(x, \partial U))$, so $B(x, \operatorname{dist}(x, \partial U)) \subseteq E$. The set $E$ is also closed in $U$ because $E = u^{-1}(\{M\}) \cap U$ and $u$ is continuous.
If $U$ is [connected](/page/Connectedness), the only subsets of $U$ that are both open and closed are $\varnothing$ and $U$. Since $x_0 \in E \neq \varnothing$, we conclude $E = U$, so $u \equiv M$ in $U$. This proves the strong maximum principle (ii).
[guided]
We have shown that any point where $u = M$ has an entire ball neighbourhood where $u = M$. Define the level set:
\begin{align*}
E := \{ x \in U : u(x) = M \}.
\end{align*}
We claim $E$ is both open and closed relative to $U$:
**$E$ is open:** If $x \in E$, then applying the mean-value argument from the previous step with $x$ in place of $x_0$ shows $u \equiv M$ on $B(x, \operatorname{dist}(x, \partial U))$, so this ball is contained in $E$.
**$E$ is closed in $U$:** Write $E = u^{-1}(\{M\}) \cap U$. The singleton $\{M\}$ is closed in $\mathbb{R}$, and $u: U \to \mathbb{R}$ is continuous, so $u^{-1}(\{M\})$ is closed in $U$, hence $E$ is closed in $U$.
Now we use the hypothesis that $U$ is [connected](/page/Connectedness). A connected topological space has no proper non-empty clopen subsets. Since $E \subseteq U$ is open, closed, and non-empty ($x_0 \in E$), we must have $E = U$. Therefore $u \equiv M$ throughout $U$, proving the strong maximum principle (ii).
[/guided]
[/step]
[step:Deduce the weak maximum principle (i) from the strong form]
If $u$ is not constant on $U$, the strong maximum principle (ii) applied to each connected component of $U$ shows that $u$ cannot attain its maximum at any interior point. Since $u \in C(\overline{U})$ and $\overline{U}$ is compact (assuming $U$ bounded), the maximum of $u$ on $\overline{U}$ is attained. It must therefore be attained on $\partial U$:
\begin{align*}
\max_{x \in \overline{U}} u(x) = \max_{x \in \partial U} u(x).
\end{align*}
If $u$ is constant, the equality holds as well. By applying the same argument to $-u$, the analogous minimum principles follow.
[/step]