Forums Register Login
Inheritence Problem..
A reference variable can be assigned a reference to any subclass derived from superclass but the reverse in not true . Why ??

Class first
Class second extends first

Class mainone
public static void main (string[] args)
second sec = new second();
first fir = new first();

sec = fir //Error
fir=sec ; // Works

Why ??
Because a "second" object is a "first" object as well, but a "first" instance is not an instance of "second".

Consider what would happen if you could do this, and then called one of the methods that "second" declares which "first" doesn't have.
I got it. Thanks Sir, thanks a lot....

This thread has been viewed 487 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 18, 2018 06:12:48.