V Aravind wrote:Can we use a derived class pointer to point to a base class method? I ve tried it. it is showing error if i used to point a base class method through a derived class object. But when i use static blocks alone in both the classes, the program is executing successfully. Whats the reason behind it?
if you are talking in java terms then their is no pointer.........
lets see
then you cannot cast the sub class object to a superclass because when a superclass object is created then it doesnot know anything about subclass so class cast excwption is thrown..........
for example for above code.......
//will give class cast exception because at runtime when super class object is created then it doesnot know anything about sub.
hope this helps you.............