I am asked to say what does this code do but I really cannot figure it out.
I've tried to execute it in netbeans and got the answer 6
but really cannot understand why.
public class Quattro {
int x = 5;
Quattro s = this;
Quattro f(){
s.s.s.x++;
return s;
}
void g(){System.out.println(x);}
public static void main (String[] args){
Quattro a4 = new Quattro();
a4.f().g();
}
}
Question 1: What does Quattro s = this;
do? Am I declarind a pointer to my self? If so, it means that I can write
Quattro f(){
s.s.s.x++;
return s;
}
or even
Quattro f(){
s.s.s.s.s.s.s.s.x++;
return s;
}
and I'll always get the same result because I'm in a loop?
Question 2: I do not understand what a4.f().g();
does... seems so weird to me.