static的介绍 静态和非静态

static的介绍

静态遍历:建议直接使用类名进行访问

静态方法:在类里面全局存在

import static java.long.Math.random  //静态导入包 可以直接调用random 不需要Math.random来调用
​
public class student{
​
• {
  //匿名比静态稍晚
​
• //匿名代码块
​
• }
​
• static{
  //静态代码块最早执行(比构造器还早)
  //static 代码块只执行一次,其余的(包括匿名代码块)只要对象实例就要再被执行
​
• //static代码快
  //静态代码块
​
• }
​
}
 

 

posted @ 2022-06-17 10:05  YangWF  阅读(51)  评论(0)    收藏  举报