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 } }
it flower
object eligible garbage collection. rose object still referred both reference variable f
, r
.
Comments
Post a Comment