'Adherence' of continuous functions, well-defined and continuous function 
Let $X=A\cup B$ and $A,B$ closed. Let $f: A\to Y$ and $g: B\to Y$ be continuous functions and $f(x)=g(x)$ for all $x\in A\cap B$.
Show that $h: X\to Y$, $h(x)=\begin{cases} f(x),  \text{if}\,\,x\in A \\ g(x), \text{if}\,\, x\in B\end{cases}$
is well-defined and continuous.

To show, that $h$ is a well-defined function, should be easy.
We have to show, that $h$ is 'left-totally'. Hence for every $x\in X$ exists a $y\in Y$ with $h(x)=y$.
And 'right-unique'. Hence for every $x\in X$ and $y, y'\in Y$ with $h(x)=y$ and $h(x)=y'$ is $y=y'$.
It is immediatly clear, that $h$ is 'left-totally' since $X=A\cup B$ and the definition of $h(x)$.
Also it is immedialty clear, that $h$ is 'right-unique', because $f$ and $g$ are functions (which are 'right-unique').
You could seperate some cases. For example: If $x\in A\setminus B$ and $h(x)=y$
and $h(x)=y'$. Then is $h(x)=f(x)=y$ and $f(x)=y'$. But $f$ is 'right-unique' and therefor $y=y'$.
The same for $x\in B\setminus A$ and $x\in A\cap B$.
Actually, I do not even know, why this is a task. Maybe just to refresh what is meant with 'well-defined', or is there something to think about here?
And $h$ is continuous, because it is continuous in every point.
Am I missing something here? What has this to do with $A, B$ beeing closed?
Thanks in advance.
 A: Showing that $h$ is well-defined is straightforward and you've done it already. Here's the part about continuity:
A well-known theorem in general topology, which is straightforward to prove, says that

A function $\varphi: X \to Y$ between two topological spaces $X$ and $Y$ is continuous if and only if the pre-image of any closed set in $Y$ is closed in $X$.

Now let $Y_0 \subseteq Y$ be a closed set in the topological space $Y$. Then what is $h^{-1}[Y_o]$? Since $X= A \cup B$, one can write set-theoretically that
$$h^{-1}[Y_0]=\big\{x\in A: f(x)\in Y_0\big\}\cup\big\{x\in B: g(x)\in Y_0\big\}$$
which tells us that $$h^{-1}[Y_0] = f^{-1}[Y_0]\cup g^{-1}[Y_0]$$
Since $f$ is continuous, $f^{-1}[Y_0]$ is closed in $A$, since $A$ itself is closed in $X$ (this is where the assumption that $A$ and $B$ are closed in $X$ becomes useful), $f^{-1}[Y_0]$ is closed in $X$. 
A similar argument for $B$ shows that $g^{-1}[Y_0]$ is closed in $X$. Hence, $h^{-1}[Y_0]$ is closed in $X$. Q.E.D.

A possible reason that this exercise was given is to emphasize that being open or closed are relative concepts. To move from being closed in a subspace to a superset is not trivial and one needs extra assumptions to make this move. Here, the assumption that $A$ and $B$ are closed in $X$ allows us to conclude that $f^{-1}[Y_0]$ and $g^{-1}[Y_0]$, not only are closed in $A$ and $B$ respectively, but they're closed in $X$ as well. 
Addendum: In fact, we have the following characterization of closed sets in the subspace topology.

Proposition. Let $Y$ be a subspace of a space $X$. Then a set $H\subseteq Y$ is closed in $Y$ if and only if $H=F\cap Y$ for some closed set $F$ in $X$.

To see the proof, which follows the same line of thought as in your comment, see Brian M. Scott's post on this question.
