+ 7
Please Help.explain this. why? how?
class Program { int x=2; int z=f(f(x)); int f(int x){ return x+x; } public static void main(String[] args) { Program obj = new Program() ; System.out.println(obj.z); } }
3 Antworten
+ 9
f(2)=2+2=4
f(4)=4+4=8
Output is 8.
+ 6
The output would be 8. When you creating a new object it sets x=2. And then it calls a function to evaluate z. But in first function call the parameter is the number, that a subfunction should return.
z=f(f(x))=f(x+x)=f(2+2)=f(4)=4+4=8.
+ 2
Thanks all.