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修饰的方法不可见。
The method sex() from the type PublicUtilTest is not visible
译:PublicUtilTest类型的方法sex()不可见
可以跨包调用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()。
四、