final and static

static和final的意义是不同的,
static修饰的时候代表对象是静态的,而final修饰的时候代表对象只能赋值一次,
他们连用的时候是因为定义的那个对象既要它是静态的,也要求它的值不能再被修改。
举例说明:
static int a=1;
static final b=1;
这里a和b的区别在于,a在程序里可以被重新赋值为2或3或等等的整数,而b在程序里不能被重新赋值,b永远都为1,也就是说b是一个常量。
final int c=1;
static final b=1;
这里c和b的区别在于,b存放在静态空间,不会在程序运行时被释放,它永远占着内存直到程序终止,而c在程序用完它而不会再用到它的时候就会被自动释放,不再占用内存。

当一个常数或字符串我们需要在程序里反复反复使用的时候,我们就可以把它定义为static final,这样内存就不用重复的申请和释放空间。
  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. The keyword final is used to declare a constant variable, which means the value of the variable cannot be changed once it is assigned. It can also be used to make a method or class immutable, which means they cannot be overridden or extended by any subclass. The keyword static is used to define a class-level or static variable, method, or block. A static variable belongs to the class and is shared by all instances of the class. A static method can be called without creating an instance of the class. A static block is used to initialize static variables when the class is loaded. 2. The Parent Delegation Model is a design pattern used in object-oriented programming, where a subclass delegates some or all of its functionality to its parent class. In this model, the parent class is responsible for providing the common functionality to all its subclasses, while the subclasses only add or modify their own specific functionality. This model is used in many programming languages, including Java, where it is implemented through the concept of inheritance. In Java, a subclass can inherit the properties and methods of its parent class using the extends keyword. The subclass can then use these inherited properties and methods, as well as add its own properties and methods. The Parent Delegation Model is a powerful technique that promotes code reuse and reduces duplication of code. It also makes it easier to maintain and update code, as changes made to the parent class are automatically inherited by all its subclasses.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值