example object casting
class Dog
{
}
class Beagle extends Dog
{
}
class Kennel
{
public static void main(String arg[])
{
Beagle b1=new Beagle();
Dog d1=new Dog();
Dog d2=b1;
Beagle b3=(Beagle)d2; // valid
Beagle b4=d2; // not vlaid
Beagle b2=(Beagle)d1; // valid
}
}
0 comments:
Post a Comment