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 ??

Have the determination of mirror which never fails to reflect in spite of being broken into pieces.<br /> <br />Kiss the hands you cannot bite.<br /> <br />An Optimist is one who starts taking a bath when he accidentally falls into the water.

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.

Shivit Agarwal

Ranch Hand

Posts: 82

posted 9 years ago

I got it. Thanks Sir, thanks a lot....

Have the determination of mirror which never fails to reflect in spite of being broken into pieces.<br /> <br />Kiss the hands you cannot bite.<br /> <br />An Optimist is one who starts taking a bath when he accidentally falls into the water.