java 修饰符含义_java-static修饰符的含义

静态常量

public final class Math {

/**

* Don't let anyone instantiate this class.

*/

private Math() {}

/**

* The {@code double} value that is closer than any other to

* e, the base of the natural logarithms.

*/

public static final double E = 2.7182818284590452354;

/**

* The {@code double} value that is closer than any other to

* pi, the ratio of the circumference of a circle to its

* diameter.

*/

public static final double PI = 3.14159265358979323846;

在Math类中定义了一个静态常量,在程序中采用Math.PI的形式获得这个常量。

44eb31d136219491880b1b2cf185a80e.png

public final class System {

public final static PrintStream out = null;

另一个多次使用的静态常量是System.out。

因为out被声明为final,所以,不允许再将其他打印流赋给它。

静态方法

静态方法是一种不能向对象实施操作的方法。

例如,Math类的pow方法就是一个静态方法。

可以认为静态方法是没有this参数的方法。

public final class Math {

public static double pow(double a, double b) {

return StrictMath.pow(a, b); // default impl. delegates to StrictMath

}

cc0ccea0c76ff146d8af37ecef38f5d0.png

main方法不对任何对象操作。事实上,再启动程序时还没有任何一个对象。静态的main方法将执行并创建程序所需要的对象。

注释

在局绝大多数的面向对象程序设计语言中,静态域被称为类域。术语" static "只是沿用了C++的叫法,并无实际意义。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值