Why this keyword only in Java Non static Context? | Java Tutorial

This Java Tutorial”Why this keyword only in Java Non static Context” explains clearly what is ‘this’ keyword and why we cannot use ‘this’ keyword inside static context of java application.


 

Why ‘this’ only inside Non static Context?

  • This below diagram explains clearly and more generally.

java ‘this’ keyword in static and non-static contexts

 

Step-1 : Student Entered into Reception (static area of institute)

Step-2 : Student asking the Admin that “Where is the java class?”

Step-3 : Admin should address by specifying room number (object reference variable). Admin cannot use the word ‘this’ to address a specific room from Reception(static context).

Step-4 : Student entered to Java class with the information provided by ADMIN.

Step-5 : Student again asking the question to other students present in java class that “Where is the Java class?”

Step-6 : Other students can answer “this is the Java class”. Hence they can use ‘this’ keyword inside non static context.

 

Share this