我用抽象类写了个代码,但是在主函数提示不能实例化
主函数
package com.Shape;
import java.util.Scanner;
public class T {
public static void main(String[] args) {
// TODO Auto-generated method stub
Circle obj1=new Shape();//提示不能实例化Shape
obj1.mianji();
}
}
父类
package com.Shape;
import java.util.Scanner;
public abstract class Shape {
public abstract double mianji();
}
子类
package com.Shape;
import java.math.*;
import java.util.Scanner;
public abstract class Circle extends Shape {
double mj;
double r;
@Override
public double mianji() {
// TODO Auto-generated method stub
System.out.println("请输入圆的半径:");
Scanner in=new Scanner(System.in);
double r=in.nextDouble();
mj=Math.PI*(r*r);
System.out.println("圆的面积:"+mj);
return r;
}