This indicates the "current object" and cannot be used in static methods.
As you know, there are many pulling objects, variable pulling, threads, and so on.
1. This is used to indicate global variables.
Public class testclass {int X, Y; void testshow (int x, int y) {This. X = x; // This. X is the X in int X, Y. X is the X this. Y = y ;}} from us ;}} |
2.
public class TestClass { int x; int y; static void showtest(TestClass tc){ System.out.println(tc.x+" "+tc.y); } void seeit(){ showtest(this); } public static void main(String[] args){ TestClass p=new TestClass(); p.x=9; p.y=10; p.seeit(); }} |
In this Code, showtest (this), where this is to pass the current instantiated P to the showtest method, and thus it runs. |
The class name is used to access static members;
Public class test { Private float F = 1.0f; Int M = 12; Static int n = 1; // Public static void main (string [] ARGs ){ Public void main (string [] argc ){ Test T = new test (); Test. n = 10; } } |
Object names can access static and non-static members
Public class test { Private float F = 1.0f; Int M = 12; Static int n = 1; // Public static void main (string [] ARGs ){ Public void main (string [] argc ){ Test T = new test (); Test. n = 10; T. M = 10; T. N = 10; } } |