This
This can only be used within a method, representing a reference to the object that invoked the method or property.
Public class MyClass {
Private String name;
Public MyClass () {}
Public MyClass (String name) {
This (); Must be at the top of this constructor, and a constructor can only be used once for this
this. Name = name;
}
Public void fun1 () {
String s = this. Name;
this. fun2 ();
}
Public void fun2 () {}
} Static
static data, which cannot invoke non-static data, can be reversed.
Static can modify variables, blocks of code, methods, classes (only internal anonymous classes).
Public class MyClass {
private static String name;
Public static void fun () {}
Public static void main (string[] args) {
System.out.println (Myclass.name);
Myclass.fun ();
}
}
Static data is initialized when class is loader; the initialization of the property of the class is initialized before the constructor call, so the following code, the value of I, first 0, then constructs the method to modify it to 7.
Public class MyClass {
private int i;
Public MyClass () {
i = 7;
}
} Super
Super and this, you can refer to constructors, properties, and methods, but are all of the parent classes:
Public class MyClass extends A {
Public MyClass () {
Super (); constructor, must be top, one
}
void Fun () {
System.out.println (Super. i); Property
Super. Funa (); Method
}
}
class A
int i;
Public A () {}
void Funa () {}
}