问答详情
源自:10-3 Java 中的抽象类

我的这个作业合格吗?求评价!

package tuxing2;


public abstract class tuxing {

    static int a = 4;

    static double π = 3.14;

    static int b = 5;

public abstract void Area();//面积

    public abstract void Perimeter();//周长

}

-----------------------------------------------------------------------------------------------------------------------------------------------

package tuxing2;


public class Round extends tuxing {


@Override

public void Area() {//圆形的面积

// TODO Auto-generated method stub

        System.out.println("圆形的面积= "+π*a*a);

}


@Override

public void Perimeter() {//圆形的周长

// TODO Auto-generated method stub

System.out.println("圆形的周长= "+2*π*a);


}

}

-----------------------------------------------------------------------------------------------------------------------------------------------

package tuxing2;


public class Rectangle extends tuxing {


@Override

public void Area() {//矩形的面积

// TODO Auto-generated method stub

System.out.println("矩形的面积= "+a*b);


}


@Override

public void Perimeter() {//矩形的周长

// TODO Auto-generated method stub

System.out.println("矩形的周长= "+(a+a+b+b));


}

}

-----------------------------------------------------------------------------------------------------------------------------------------------

package tuxing2;


public class Test {


public static void main(String[] args) {

// TODO Auto-generated method stub

tuxing TX1 = new Round();

TX1.Area();

TX1.Perimeter();

tuxing TX2 = new Rectangle();

TX2.Area();

TX2.Perimeter();


}


}


提问者:java_羽恋 2018-08-06 10:51

个回答

  • Myzking
    2018-08-06 13:34:53
    已采纳

    一般写类名的时候首字母大写,方法首字母小写。而且抽象类是声明方法,可以设置参数,实现方法时传值进行相关计算,public void area(double a,double b).