java编译时出现Cannot instantiate the type Circle


package com.imocc;


public class initial   {


/**

* @param args

*/

public static void main(String[] args) {

Shape do1 = new Circle();

Shape do2 = new Rectangle();

do1.acount1();

do2.acount2();

// TODO Auto-generated method stub


}



// TODO Auto-generated method stub



}


神不在的二月
浏览 7563回答 3
3回答

虛無縹緲丶

你的Circle类是一个抽象类 在Java中不能直接new 抽象类

神不在的二月

package com.imocc;public abstract class Circle extends Shape {public int r = 4;public double x ,y; public void acount1() { // TODO Auto-generated method stub x = 3.14*r*r; y =2 * 3.14 * r; System.out.println("圆形的周长是:"+ y  +"圆形的面积是:"+ x ); } public void acount2() { // TODO Auto-generated method stub }}

神不在的二月

package com.imocc;public abstract class Shape { public abstract void acount1(); public abstract void acount2();}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android
Java