static关键字

1. static关键字,修饰属性、方法还有代码块,表示类的成员。还可以import static类的方法或者属性。

package com.oop.demo7;
import static java.lang.Math.random;

public class Application {

public static void main(String[] args) {

Person p1 = new Person();
System.out.println("=================");
Person p2 = new Person();

System.out.println(random());
}
}

package com.oop.demo7;

public class Person {

{
System.out.println("匿名代码块");
}

static
{
System.out.println("static coding block");
}

public Person() {
System.out.println("object initiated.");
}
}

2. final类,无法被继承。

posted @ 2020-11-28 00:26  浪淘  阅读(96)  评论(0)    收藏  举报