请问一个关于类型转换的有关问题

请教一个关于类型转换的问题
看如下代码:
Object o="gh"; //o的类型应为Object
System.out.println(o.getClass()); //但getClass()方法显示结果为:o的类型为String
问题:
o的类型到底是Object还是String?上述代码在内存的运行的过程是什么?




------解决方案--------------------
getClass

public final Class<?> getClass()
Returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class. 
The actual result type is Class<? extends |X|> where |X| is the erasure of the static type of the expression on which getClass is called. For example, no cast is required in this code fragment:

Number n = 0; 
Class<? extends Number> c = n.getClass(); 

------解决方案--------------------
这个问题很简单,o的运行时的类型是String,而你用Object进行的声明,在编译期间的检查的时候o是Ojbect类型
如果没有强制类型转换为String,那么是不能使用String特有的方法,只能使用Object类型的几个方法

Java语言里面有自动向下转型的机制,就像你这个例子,String是Object的子类,o的实际类型是String虽然 声明的时候是Object但是Java运行的时候会把o当做String进行处理的
探讨

o的类型到底是Object还是String?