Takes this Example:
Class X{int i;void functionX(){S.o.p(i); // S.o.p = System.out.printlnS.o.p(j);}}Class Y extends X{int j;void function Y(){S.o.p(j);S.o.p(i);}public static void main(String[] args){Y yObject = new Y();yObject.j = 20;yObject.i = 30;yObject.functionY();yObject.functionX();}}
Explanation :
As Soon as JVM Encounters a Main Method it creates an Object of Class Y. Loads all the Non-Static Members into the Object and loads the Constructor of the Class Y.
After the Starts executing the Constructor of the Class Y. before Start Executing it checks Whether this Class(Class Y) extends any class. if that is the Case,
it create the Object of the Extended class , and load non - static Members into that Object and start Executing the Constructor of that Class(here Class X).
NOTE : Able to Change the value of a Variable of an Object whose Reference is Not Directly available to us. Here We are Available change the i value eventhough we did not create any Object of class X.
No comments:
Post a Comment