Question about the output voltage of an op-amp. (ua741)
As Oli said, in the first case you are operating it out of spec since the input common mode range does not extend to the positive supply.  In the second case the inputs are just floating so you don't know what voltage they end up at.

However, even if you were to short the two inputs together and hold them somewhere within the valid range, like 4.5V, you would still likely not get 0V out.  This is because the opamp is not perfect and has some input offset voltage.  This is essentially a small error voltage added to one of the inputs.  Let's say for example this opamp this day at this temperature at this input voltage has 2 mV input offset.  When you tie the two inputs together, the opamp will see this 2 mV input instead of the real 0V input.  That apparent input will be multiplied by the opamp's open loop gain, which is probably at least 100k or so.  2mV * 100k = 200V.  Obviously this amp can't produce 200V, so it will drive it's output as far as it can towards the positive supply rail.

Note that the input offset could just as well have been -2mV, in which case the output would drive as far as it can towards the negative supply rail.

Input offset voltage is a reality of opamps, and is one of the issues that need to be considered in designing a circuit with them.