【发布时间】:2016-04-18 11:16:59
【问题描述】:
错误:mul(int,int) 在乘法中具有受保护的访问权限
想到我做错了什么?
public class Multiplication{
protected int mul(int a,int b){
return (a*b);
}
}
class ImplimentPkg extends Multiplication {
public static void main(String args[]){
Multiplication obj=new ImplimentPkg();
//Here's the error
System.out.println(obj.mul(2,4));
}
protected int mul(int a,int b){
System.out.println("");
return 0;
}
}
【问题讨论】:
-
“这里的错误”到底是什么意思?
-
System.out.println(obj.mul(2,4)) 无法访问自己的方法..它被覆盖了..!
-
类
ImplimentPkg与Multiplication是否在不同的包中?如果是,则发生错误是因为mul受到保护,您无法从其他包访问它。 -
为什么我们不能访问其他包??如果我没记错的话,我们可以使用带有 procted 方法的继承吗?
标签: java