Tim Lim wrote:...since I have 2 classes with similar attribute, name just that they are of different packages....
It's helpful to think of the package as
part of the fully qualified name of the class rather than merely as a place where you're storing the class.
In that light,
com.ok.alpha.YourClass does not have the same name as, and is not identical to, com.ok.beta.YourClass even if they have similar (abbreviated) class names and members.
This fact implies, as others have noted above, that the possibility of casting will depend on whether the two occupy appropriate positions in an inheritance tree. One must be a subclass of the other.