"C:\Program Files\Java\jdk-14.0.1\bin\java.exe""-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\lib\idea_rt.jar=2615:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\bin"-Dfile.encoding=UTF-8-classpath C:\Users\Jinfanglin\IdeaProjects\javaSe\out\production\javaSe api_demo.DemoStaticFiled
jinfl*17
haolh*16
jinfl*17**1705*1
haolh*16**1705*2
Process finished with exit code 0
"C:\Program Files\Java\jdk-14.0.1\bin\java.exe""-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\lib\idea_rt.jar=3758:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\bin"-Dfile.encoding=UTF-8-classpath C:\Users\Jinfanglin\IdeaProjects\javaSe\out\production\javaSe api_demo.StaticMethod
普通方法
静态方法
静态方法
Process finished with exit code 0
package api_demo;import CommonClass.Person;/*
* 静态代码块格式:
* public class leimign{
* static{
* // 静态代码块的内容
* }
* }
* 特点:当第一次用到本类的时候,静态代码块执行唯一的一次
* 静态内筒总是优先于非静态
* */publicclassstaticCode{publicstaticvoidmain(String[] args){
Person one =newPerson();
Person two =newPerson();}}
"C:\Program Files\Java\jdk-14.0.1\bin\java.exe""-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\lib\idea_rt.jar=5407:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\bin"-Dfile.encoding=UTF-8-classpath C:\Users\Jinfanglin\IdeaProjects\javaSe\out\production\javaSe api_demo.staticCode
静态代码块
Process finished with exit code 0
1、static修饰变量package CommonClass;public class StudentStaticx { private int id; private String name; private int age; public static String room; private static int idcounter=0; public StudentStaticx(){ this.id=++idcounter;