修饰符

Illegal modifier for the method name; only public, protected, private, abstract, static, final, synchronized, native & strictfp are permitted

方法名称的非法修饰符; 只允许使用public,protected,private,abstract,static,final,synchronized,native和strictfp

 一、public

可以修饰类、变量、方法、接口、枚举、注解

 

 

public类中对于不同修饰符修饰的变量的访问

在同一包结构下,可以对public、package、protected修饰的变量进行访问;在不同包结构(子包也不例外)下,无法访问除public修饰的方法。

 

public类中对于不同修饰符修饰的方法的访问

在同一包结构下,可以对public、package、protected修饰的方法进行访问;在不同包结构(子包也不例外)下,无法访问除public修饰的方法。

 

二、protected

不可继承其它包内的非public类

PublicUtilA cannot be resolved to a type

译:PublicUtilA无法解析为某种类型

protected可以跨包继承

The method PublicA.description() does not override the inherited method from PublicUtilTest since it is private to a different package

译:PublicA.description() 方法不会覆盖PublicUtilTest中的继承方法,因为它是私有的来自不同的包

 

同一个包内进行继承可继承包权限及以上的方法。

 

三、private

若private修饰的私有方法,未被调用,会出现警告。不影响使用,但要尽量避免从未使用过的方法和变量出现,减少代码冗余。

The method speak() from the type PublicUtilTest is never used locally

译:PublicUtilTest类型的方法speak()从不在本地使用

 

 private只能在本类其他方法中被调用,无法由对象实例直接调用。

通过Change visibility of 'speak()' to 'package'后会变成无修饰符方法 void speak(),可实现对象实例调用,但仅限于本包内,包权限的方法没有修饰符如PublicUtilA.description()。

 >>>>>>>>>>>>>待完善<<<<<<<<<<<<<<

转载于:https://www.cnblogs.com/feiyang930112/p/11302283.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值