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
}
Run Code Online (Sandbox Code Playgroud)
}
public class Rectangle extends Shape
{
public void print()
{
System.out.println("in class Rectangle");
//super.print();
}
}
Run Code Online (Sandbox Code Playgroud)
问:为什么私有函数不显示多态行为?而我们仍然压倒最终方法?它的调用基类功能为什么?