Bess_0_
2016-04-10 22:53
public abstract class Shape{ public abstract void Circle(); public abstract void Area(); } public class Rectangle extends Shape{ int a=2; int b=3; public void Circle(); public void Area(); System.out.println("矩形的周长="+2*(a+b)); System.out.println("矩形的面积="+a*b); } public class Circle extends Shape{ double r=3.15; double P=3.14; public void Circle(); public void Area(); System.out.println("圆形的周长="+2Pr); System.out.println("圆形的面积="+Pr*r); } public static void main(Spring[] args){ Shape i=new Rectangle(); i.Circle(); i.Area(); Shape j=new Circle(); j.Circle(); j.Area(); }
abstract class Shape{ public abstract void Circle(); public abstract void Area(); } class Rectangle extends Shape{ int a=2; int b=3; public void Circle(){ System.out.println("矩形的周长="+2*(a+b)); } public void Area(){ System.out.println("矩形的面积="+a*b); } } class Circle extends Shape{ double r=3.15; double P=3.14; public void Circle(){ System.out.println("圆形的周长="+2*P*r); } public void Area(){ System.out.println("圆形的面积="+P*r*r); } } public class Test{ public static void main(String[] args){ Shape i=new Rectangle(); i.Circle(); i.Area(); Shape j=new Circle(); j.Circle(); j.Area(); } }
子类输出语句要放在Cirlcle()和area()方法的大括号里
public void zhouzhang() {
// TODO Auto-generated method stub
int zz=(a+b)*2;
System.out.println("矩形周长为:"+zz);
}
main函数应该放在一个public类里
Java入门第二季 升级版
530655 学习 · 6091 问题
相似问题