【发布时间】:2015-10-29 18:39:55
【问题描述】:
我在如何在我的主程序中声明子类时遇到了麻烦。
我有一个名为 Shapes 的抽象超类和 4 个子类(Rectangle、Triangle、Circle、Square);
我知道如果我想使用超类,我会创建一个新变量:
private Shapes shapes;
然后我将变量分配给超类:
shapes = new Shapes();
我认为你可以像这样声明一个子类:
private Shapes square;
//
square = new Square();//Square is a sub-class of Shapes.
请帮忙。
【问题讨论】:
标签: java inheritance