Assume I have a method which returns object of class A
A getItem(int index)
Now I have following line of code, (I assume B is subclass of A)
B b = (B) obj.getItem(i);
but before this I have to make sure that I can typecast it into B as getItem can return object of some other subclass, say C, of A 
Something like this
    if(I can typecast obj.getItem(i) to B) {
             B b = (B) obj.getItem(i);
    }
How I can do this?
 
     
     
     
     
    