The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

casting from a superclass to a subclass

Posted by tejinder singh on January 30, 2001 at 8:56 AM

if we cast from a superclass object to a subclass object e.g
class a{}
class b extends a
{}
class c
{
public static void main(String s[])
{
a a1=new a();
b b1=new b();
b1=(b)a1;
}
}
this gives a classcastexception at runtime however when we cast objects of class object to our own class there is no cast exception .kindly explain the same .kindly inform me at my email where i can look for the answer.



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us