1 package com.Lucky.oop;
2 /*
3 static
4 */
5 public class staticMethod {
6 private String name;
7 private static int score;
8
9 public static void add(){
10 System.out.println("static的add");
11 }
12
13 public void sub(){
14 System.out.println("不是static的sub");
15 }
16
17 public static void main(String[] args) {
18 //调用静态方法
19 add(); //或者staticMethod.add();
20 //调用非静态方法
21 staticMethod method = new staticMethod();
22 method.sub();
23
24
25
26 }
27
28 //////////////////////拓展:代码块//////////////////
29 static{
30 System.out.println("最先执行的,有且只执行一次");
31 }
32 {
33 System.out.println("最二执行的");
34 }
35
36 public staticMethod() {
37 System.out.println("第三执行的:构造器方法");
38 }
39 }