我有一个超类Shape.
Java接受某种形状的颜色,以及几个子类来计算不同多边形的区域.我创建了一个主类,打印出用户想要计算的不同多边形选项.
public static void choices() {
System.out.println("What do you want to compute?");
System.out.println("a. Rectangle");
System.out.println("b. Triangle");
System.out.println("c. Trapezoid");
}
我用了一个开关盒.
case 'a': {
System.out.print("Enter width: ");
double width = input.nextDouble();
System.out.print("\nEnter height: ");
double height = input.nextDouble();
.....
}
问题是,我如何调用我的子类Rectangle(扩展超类Shape),其中包含将显示用户输入并计算区域的方法?它是否正确?
Shape rec = new Rectangle();
如果是,当我编译它时,我得到一个错误’找不到符号构造函数Rectangle …’
请帮忙.