• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why does line 3 cause Class Cast Exception where as line 4 doesn't

Thx
[ April 06, 2004: Message edited by: Mary Cole ]
 
Ashok C. Mohan
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In line 3 u r trying to cast a base class object to a derived class,which causes the compile time error,as this does not make any sense.(Only derived class objects can be casted to base class objects.
In line 4 though u r trying to cast the interface reference to the base class,the underlying object to which the reference i is pointing is a base class object,so casting a base class object to itself does not cause a compile time error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic