Originally posted by reehan ishaque:
when class is instantiated, the first thing happens is the initialization of class members in the order they declared. here 'i' will be initialized first which causes call to givemej() which returns j with '0' cuz the statement 'int j=10;'hasnt been executed yet. this causes value of 'i' to be printed zero.
if what reehan has explained above is the reason for the output, then that means that all the variables are first of all initialized to their default values when a class is instantiated.Irrespective of their declaration and initialization at the same line as in the code.Which means when i is later initialized with the result of givemej()method, j was not a undefined variable for the class.instead j was having the initial value 0(which later got changed to 10).
this is what i think.can some1 tell me if my reasoning is correct or not?
rajashree.