Is g a keyword?
g[x_] := x^2
generate an error. But if I replace g with f or h, I'll get 4. Why?
Perhaps you previously assigned some value to g.
and see what Mathematica has been told about g.
Or click Evaluation on the menu bar, then Quit the Kernel, then Local, then Quit and that should forget any prior assignments. Try your g[x_]:=x^2;g after that.
Note: Sometimes Mathematica will consider two thing next to each other, sometimes even on two adjacent lines, as being multiplied together. Using semicolons to separate things will tell Mathematica those are two separate things and not to be multiplied.