[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....
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss


This thread has been viewed 476 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 22, 2018 08:57:54.