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()。
>>>>>>>>>>>>>待完善<<<<<<<<<<<<<<