Rajendra,
My two cents on your question...
If the JAVA compiler didn't allow your syntax, then almost all code that access the Collection Framework would all be broken. The collections store everything as an java.lang.Object. When you get the Object out of the collection, you must cast it to the specific type.
For example,
java.util.List list = new java.util.ArrayList();
list.add(new
String("Rejendra"));
list.add(new String("Peter"));
list.add(new String("Anil"));
for (int i = 0; i < list.size(); ++i) {
// Notice the cast, because get() return an Object.
String strObj = (String)list.get(i);
System.out.println(strObj);
}
NOTE, all class subclass java.lang.Object.
-Peter