[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....
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database


This thread has been viewed 499 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jan 18, 2019 13:45:12.