Java Modifiers

Java Modifiers 大体可以分为两类:

     1) Access modifiers : public, protected, default, private

     2) Non- Access modifiers : strictfp, final and abstract

        Below are the modifiers for key word class:
       1.public: The class can be used anywhere

       2.abstract: The class is an abstract class and no instance of it can be generated

       3.final: The class cannot be inherited

       4.strictfp(strict floating point): Make the floating-point arithmetic in the class evaluated strictly. This ensures the interoperability of the floating-point calculation.

 

The following table shows what Access Modifiers are appropriate for classes, nested classes, member variables, and methods:

 ClassNested classMethod, or Member variableInterfaceInterface method signature
publicvisible from anywheresame as its classsame as its classvisible from anywherevisible from anywhere
protectedN/Aits class and its subclassits class and its subclass, and from its packageN/AN/A
package (default)only from its packageonly from its packageonly from its packageonly from its packageN/A, default is public
privateN/Aonly from its classonly from its classN/AN/A

If a class has public visibility, the class can be referenced by anywhere in the program. If a class has package visibility, the class can be referenced only in the package where the class is defined. If a class has private visibility, (it can happen only if the class is defined nested in an other class) the class can be accessed only in the outer class.

If a variable is defined in a public class and it has public visibility, the variable can be reference anywhere in the application through the class it is defined in. If a variable has package visibility, the variable can be referenced only in the same package through the class it is defined in. If a variable has private visibility, the variable can be accessed only in the class it is defined in.

If a method is defined in a public class and it has public visibility, the method can be called anywhere in the application through the class it is defined in. If a method has package visibility, the method can be called only in the same package through the class it is defined in. If a method has private visibility, the method can be called only in the class it is defined in.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值