# final,static,this,super
## final
**final **
1. final final final
2. final
3. final
final Java final Java final private final
## static
**static **
1. **:** static static Java `.` `.()`
2. **:** , (>>) .
3. **static ** : 1. 2. static
4. **(1.5 ):** `import static`
## this
this
```java
class Manager {
Employees[] employees;
void manageEmployees() {
int totalEmp = this.employees.length;
System.out.println("Total employees: " + totalEmp);
this.report();
}
void report() { }
}
```
this
- this.employees.length Manager
- this.report Manager
## super
super
```java
public class Super {
protected int number;
protected showNumber() {
System.out.println("number = " + number);
}
}
public class Sub extends Super {
void bar() {
super.number = 10;
super.showNumber();
}
}
```
Sub number Super `showNumber`
** this super **
- `super()` this
- thissuper static
****
static this super **this super **
##
- https://www.codejava.net/java-core/the-java-language/java-keywords
- https://blog.csdn.net/u013393958/article/details/79881037
# static
## static
1.
2.
3. ()
4. (1.5 )
### ()
static static Java
Java Java Non-Heap Java
HotSpot HotSpot HotSpot Java
- `.`
- `.()`
private
```java
public class StaticBean {
String name;
//
static int age;
public StaticBean(String name) {
this.name = name;
}
//
static void sayHello() {
System.out.println("Hello i am java");
}
@Override
public String toString() {
return "StaticBean{"+
"name=" + name + ",age=" + age +
"}";
}
}
```
```java
public class StaticDemo {
public static void main(String[] args) {
StaticBean staticBean = new StaticBean("1");
StaticBean staticBean2 = new StaticBean("2");
StaticBean staticBean3 = new StaticBean("3");
StaticBean staticBean4 = new StaticBean("4");
StaticBean.age = 33;
System.out.println(staticBean + " " + staticBean2 + " " + staticBean3 + " " + staticBean4);
//StaticBean{name=1,age=33} StaticBean{name=2,age=33} StaticBean{name=3,age=33} StaticBean{name=4,age=33}
StaticBean.sayHello();//Hello i am java
}
}
```
###
, ( > > ) .
```
static {
;
}
```
JVM JVM

.
###
1.
2. static
Example
```java
public class Singleton {
// private
private Singleton() {
}
// private Singleton
private static class SingletonHolder {
private static final Singleton INSTANCE = new Singleton();
}
public static Singleton getUniqueInstance() {
return SingletonHolder.INSTANCE;
}
}
```
Singleton SingletonHolder `getUniqueInstance()` `SingletonHolder.INSTANCE` SingletonHolder INSTANCE JVM INSTANCE
JVM
###
import static
```java
//Math
//*
import static java.lang.Math.*;//import static java.lang.Math.max;
public class Demo {
public static void main(String[] args) {
int max = max(1,2);
System.out.println(max);
}
}
```
##
###
Example
```java
class Foo {
int i;
public Foo(int i) {
this.i = i;
}
public static String method1() {
return "An example string that doesn't depend on i (an instance variable)";
}
public int method2() {
return this.i + 1; //Depends on i
}
}
```
`Foo.method1()` method2
```java
Foo bar = new Foo(1);
bar.method2();
```
- ..
-
### `static{}``{}`()
JVM static
( -> -> ) new new ()
> ** [issue #677](https://github.com/Snailclimb/JavaGuide/issues/677)** new new `Class.forName("ClassDemo")` Class new `Class.forName("ClassDemo")`
,,,`Arrays` `Character` `String` , .
Example
```java
public class Test {
public Test() {
System.out.print("--");
}
//
{
System.out.print("--");
}
//
static {
System.out.print("--");
}
private static void test() {
System.out.print("! --");
{
System.out.print("--");
}
}
public static void main(String[] args) {
Test test = new Test();
Test.test();//--! ----
}
}
```
```
------! ----
```
`Test.test();`
```
--! ----
```
`Test test = new Test();`
```
------
```
###
- https://blog.csdn.net/chen13579867831/article/details/78995480
- https://www.cnblogs.com/chenssy/p/3388487.html
- https://www.cnblogs.com/Qian123/p/5713440.html