Reference Variable in Java? -


my doubt reference variable 'r' referencing rose object referencing flower object.

what happend rose object now? destroyed?

i have following code:

class flower { public void smell()     // {    system.out.println("all flowers give smell, if 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 super class, valid    f.smell();           // ii   } } 

enter image description here

it flower object eligible garbage collection. rose object still referred both reference variable f , r.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -