Example 3. The maximum value of the function $y=-x-\frac{9}{x}+18(x>0)$ is ( ).
(A) 24
(B) 18
(C) 12
(D) 2
(1991～1992, Guangzhou, Fuzhou, Luoyang, Wuhan, Chongqing Junior High School League)
According to the basic inequality $a+b \geqslant 2 \sqrt{a b}(a, b >0)$, we know
$$
x+\frac{9}{x} \geqslant 2 \sqrt{x \cdot \frac{9}{x}}=2 \sqrt{9}=6,
$$

the equality holds when $x=\frac{9}{x}$, i.e., $x=3$.
$$
\begin{aligned}
\therefore y & =-x-\frac{9}{x}+18 \\
& =-\left(x+\frac{9}{x}\right)+18 \leqslant-6+18=12 .
\end{aligned}
$$

Therefore, the maximum value of $y$ is 12.