public class Shape
{
final private void print()
{
System.out.println("in class Shape");
}
public static void main(String[] args)
{
Shape shape=new Rectangle();
shape.print();
//calling shape class function
//giving output in class shape
}
}
public class Rectangle extends Shape
{
public void print()
{
System.out.println("in class Rectangle");
//super.print();
}
}
问题:为什么私有函数不表现出多态行为?
我们仍然重写最终方法?
为什么它调用基类函数?
私有函数不可见,也不能从其子函数调用;因此这是两个完全不同的函数。从子类的角度来看,没有什么可以覆盖的,因为它不知道父类甚至hasprint() 函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)