I read this in Khalid Mughal e-book.
The golden rule is that static code cannot access non-static members by their simple names. Static code is not executed in the context of an object, therefore the refrences this and super are not available.
Now, This is one of the Review Questions..
Giving the folowwing code, which statements can be placed at the indicated position without causing compilation errors?
public class ThisUsage{
int planets;
static int suns;
public void gaze(){
int i;
//....insert statements here.....
}//end of gaze
public static void main (
String [] args){;}
}//end of class
Select the 3 correct answers:
a. i = this.planets;
b. i = this.suns;
c. this = new ThisUsage();
d. this.i = 4;
e. this.suns = planets;
Except a,b and e others got compile time error. I thought that 'this' keyword cannot be used for static variables and methods. Can anyone please elaborate on it.
Also, is 'this = new ThisUsage()' statements can be a legal statement (not in this particular example or code)