1、传统静态方法的调用方式

定义一个Common类,里面有静态方法和静态常量

package com.example.common;


public class Common {
	
	public static final int AGE = 30;
	
	public static void output(){
		System.out.println("hello world");
	}
	
}

  

在另外一个包中使用

import com.example.common.Common;

public class StaticImport {
	public static void main(String[] args) {
		int a = Common.AGE;
		System.out.println(a);
		
		Common.output();
	}
	
}

  

2、静态导入使用

import static com.example.common.Common.*;

public class StaticImport {
	public static void main(String[] args) {
		int a = AGE;
		System.out.println(a);
		output();
	}
	
}

  

 

相关文章:

  • 2022-12-23
  • 2021-05-11
  • 2021-06-04
  • 2021-11-04
  • 2022-03-09
猜你喜欢
  • 2021-08-20
  • 2022-01-29
  • 2021-12-08
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2021-11-07
相关资源
相似解决方案