My doubt is the reference variable 'r' which was referencing rose object is now referencing flower object.
What happend to rose object now? Will it be destroyed?
I have the following code:
class Flower
{
public void smell() // I
{
System.out.println("All flowers give smell, if you can smell");
}
}
public class Rose extends Flower
{
public void smell() // II
{
System.out.println("Rose gives rosy smell");
}
public static void main(String args[])
{
Flower f = new Flower();
Rose r = new Rose();
f = r; // subclass to super class, it is valid
f.smell(); // II
}
}
