JAVA新手提问 编译时一直显示Square是抽象的,无法实例化,可是Square的类我没有抽象啊,为什么Circle行
发布网友
发布时间:2022-05-10 18:37
我来回答
共1个回答
热心网友
时间:2023-10-22 05:31
package com.tx.day;
abstract class Graph {
double r;
final double pi = 3.14;
int length;
int wide;
public Graph(double r) {
this.r = r;
}
public Graph(int length, int wide) {
this.length = length;
this.wide = wide;
}
public abstract void GetArea();
public abstract void GetLong();
}
class Circle3 extends Graph {
public Circle3(double r) {
super(r);
}
@Override
public void GetArea() {
System.out.println("圆形的面积为:" + pi * r * r);
}
@Override
public void GetLong() {
{
System.out.println("圆形的周长为:" + 2 * pi * r);
}
}
}
class Square extends Graph {
public Square(int length, int wide) {
super(length, wide);
}
public void GetArea() {
System.out.println("矩形的面积为:" + wide * length);
}
public void GetLong() {
System.out.println("矩形的周长为:" + 2 * (wide + length));
}
}
public class Test{
public static void main(String[] args) {
Circle3 c = new Circle3(3.0);
c.GetLong();
c.GetArea();
Square s = new Square(2, 4);
s.GetArea();
s.GetLong();
}
}