Let $h(x)$ be a piecewise function in which
$$h(x) = \begin{cases} 1+x &\text{if $x < 0$}\\ ax+b & \text{if $0\le x\le 1$}\\ 4x+2 & \text{if $x > 0$} \end{cases} $$
And also note that $h(x)$ is continuous at $x=0$ and $x=1$.
Given these implications, the following must be true, given what I see:
$$1+x = ax+b \iff x=0 $$
$$ax+b = 4x+2 \iff 0 < x\le1$$
Apparently to solve this, we use the first statement to solve for $b$ with $x=0$ and the second statement to solve for $a$ with $x=1$. However, this puzzles me.
I can kind of see how to find $b$ using this logic, since, even though $1 + x \ne h(x)$ at $x=0$, it must be equal to $ax+b$ since it's continuous and if it were not true then the function would not be continuous. But then, is $1+x,\ \,\ x < 0 = h(x)$ really a true statement?
Furthermore, with finding $a$, using the second bit, if $a$, $b$, $4$, and $2$ all constants, how can $ax + b = 4x+2$ only conditionally? It would seem clear as day given this equation $a = 4$ and $b = 2$ if this is true for any instant and then, since $a$ and $b$ are constants, the transition to $4x+2$ should be no change in the image of the function at $x > 1$. Retrospectively, it must be because this is true if $ax+b$ and $4x+2$ have the same output from $0<x \le 1$ but do not necessarily need to have the same image for all x. But also, why do I have to use $x=1$ to solve for $a$? Can't I use any real number from $(0,1]$?
Given that the function is continuous at $x=0$ and $x=1$ then we know that following is true.
$$\lim_{x \rightarrow a}f(x)=f(a)$$
For the limit to exist the left hand limit must be equal to the right hand limit
$$\lim_{x \rightarrow a^+}f(x)=\lim_{x \rightarrow a^-}f(x)=\lim_{x \rightarrow a}f(x)$$
For $x=0$
Left Hand Limit $$\lim_{x \rightarrow 0^-}h(x)=\lim_{x \rightarrow 0^-}1+x=1$$
Right hand Limit $$\lim_{x \rightarrow 0^+}h(x)=\lim_{x \rightarrow 0^-}ax+b=b$$
Equating both sides.
$$b=1$$
For $x=1$
Left hand limit $$\lim_{x \rightarrow 1^-}h(x)=\lim_{x \rightarrow 1^-}ax+b=a+b$$
Right hand limit $$\lim_{x \rightarrow 1^+}h(x)=\lim_{x \rightarrow 1^+}4x+2=6$$
For the limit to exist we must have $LHL=RHL$
$$a+b=6$$
Know that $b=1$
$$a+1=6$$
$$a=5$$
To answer your question,
1) the function is defined in such a way that they are different functions for specific interval. So, $1+x$ for $x<0$ must be a true statement.
It is already stated in the question that the functions are continuous over the point $x=1$ and $x=0$. When we say that a function is continuous at $x=a$ then we must the limit exists at $x=a$ and the $f(a)$ must exist.
2) The reason we don't use any x that is inside $(0,1]$ is because it will give us a as a parameter which may or may no satisfy the right hand limit $4x+2$. We want something that will satisfy the limit from the right side and left side.
$x=\frac{1}{3}$
$$ax+b=4x+2$$
$$\frac{a}{3}+1=\frac{4}{3}+2$$
$$a=7$$
Test at $x=1$
$$h(x)=ax+b$$
Left hand limit.
$$\lim_{x \rightarrow 1^-}h(x)=\lim_{x \rightarrow 1^-}7x+1=8$$
Right Hand limit
$$\lim_{x \rightarrow 1^+}h(x)=\lim_{x \rightarrow 1^+}4x+2=6$$
There exists a difference in limit hence we cannot have a continuous function at that point. No continuity for different limit. There is a jump discontinuity.
You can try it with other values of $x$ that is inside $(0,1]$
That is why we choose the values of $a$ and $b$ such that there is no break in the function.
Hope I don't make any mistake