[Logo]
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....
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature


This thread has been viewed 466 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 26, 2018 01:50:57.