I realy don't understand the explanation.....
Hi tsoloane,
To run this statement:
System.out.print(ga.i+" "+ga.getI());
We first need to find out the outcome of our expression : ga.i + " " + ga.getI()
Can we print something without knowing it value? No, right? So at this expression, we first need to call ga.getI() to see its value.
As we call this method, there is a println statement in that method which prints "Sub". So that's what gets pritned at first.
After that, we have the value "2" returned. Now we know the value of ga.getI(), which is "2". So we can now just print the expression. This will be "1 2".
Since "Sub" has already been printed, the output would be "Sub1 2"
Does that shed some lights?
yes, thank you very much for the explanation