This is my code
in my assumption , when the code reach line 12 its checks default constructor in mountain class its not found then go to the parent class rock then go to the parent of the rock atom and print "atom" . then come to next line 13.calls single parameter of the super rock class.will print "granite".
then again they create memory of the class with single
parameter constructor , then print "granite".
o/p should be in atom granite granite
but here out put is like atom granite atom granite .
how second time atom has came.
Code:
class Atom {
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
new Rock("granite ");
}
public static void main(String[] a) { new Mountain(); }
}
in my assumption , when the code reach line 12 its checks default constructor in mountain class its not found then go to the parent class rock then go to the parent of the rock atom and print "atom" . then come to next line 13.calls single parameter of the super rock class.will print "granite".
then again they create memory of the class with single
parameter constructor , then print "granite".
o/p should be in atom granite granite
but here out put is like atom granite atom granite .
how second time atom has came.
Comment