1--Modifier in java(java访问修饰符)

Access Modifiers && Non-Access Modifiers

在这里插入图片描述

1. Public modifier

Public modifier provides universal access which means any public class, method or variable is accessible by everyone and everywhere. (You can access a public class both within the package and outside the package).

2.Default modifier

Default classes are accessible for classes in the same package, the default attributes, methods, constructors are accessible in the same package.

3.Private modifier

Private modified attributes, methods, constructors are accessible within the declared class.

4.Protected modifier

Protected attributes, methods, constructors are accessible in the same package and subclass outside of the package.

Non-access modifiers

1. Final Modifier

Final class cannot be inherited by other classes.
Final attributes, constructor, methods cannot be overridden or modified.

2. Abstract Modifier

An abstract class can be accessed by other abstract classes, and can be inherited from other classes.
Abstract defined attributes, methods can be only used in an abstract class.

3. Static Modifier

Static methods have access to class variables (static variables) without using the class’s object (instance).
Only static data may be accessed by a static method.

4. Transient Modifier

Transient attributes, methods are skipped when serializing the object containing items.

5.Synchronized Modifier

Synchronized methods can be accessed by one thread at a time.

6.Volatile Modifier

The value of an attribute is not cached thread-locally, and it is always read from the main memory.
在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值