package override;
class Super
{
public void dosomething()
{
System.out.println("hello Super");
}
}
class sub
extends Super
{
@Override
public void dosomething()
{
System.out.println("hello sub");
}
}
public class Main
{
public static void main(String[] args)
{
Super p1=new Super();
Super p2=new sub(); // Please explain why this line is correct as constructor and //class name should be same
p1.dosomething();
p2.dosomething();
}
}
当我创建具有不同类名和不同构造函数名称的对象时,如何调用方法。就像上面突出显示的语句有不同的调用构造函数的方式