Srinivas please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it.
As for your problem, ob doesn't contain an instance of your TSub class. You assigned ts.getCls().getValue() to ob which is actually the String "In Sub" that your getValue method returns...
Your getValue() method returns a String object, and then you call toString() on that object, so toString() method on the String class will be invoked, if you invoke toString() on your TSub object, then [Sub Class] will be printed. Check the method invocation carefully.
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Object ob is assigned to a string "In Sub" and by doing so the Object ob now refers to String class whose constructor is initialized with value "In Sub".
The toString() method in Object class is over-ridden by String and Wrapper classes.Thus you can invoke the toString() method ,due to polymorphism the String class' version of toString() method runs which returns the value "In Sub".