父类 package imooc02; public abstract class Shape { public abstract void Perimeter(); public abstract void Area(); } 子类01 package imooc02; public class Rectangle extends Shape { @Override public void Perimeter() { // TODO Auto-generated method stub double a; double b; double c; double c= (a+b)*(a+b); System.out.println("长方形的周长为"+c); } @Override public void Area(){ // TODO Auto-generated method stub double a ; double b; double s; double s= a*b; System.out.println("长方形的的面积为"+s); } } 子类02 package imooc02; public class Circle extends Shape { @Override public void Perimeter(){ // TODO Auto-generated method stub double π; double d; private double c ; private double c= π*d; System.out.println("圆的周长是:"+c); } @Override public void Area(){ // TODO Auto-generated method stub double π; double d; double s; double s= π*((d/2)*(d/2)); System.out.println("圆的面积是:"+s); } } 测试类 package imooc02; public class Test { public static void main(String[] args) { Shape a1=new Rectangle(); a1.Perimeter(); a1.Area(); Shape a2=new Circle(); a2.Perimeter(); a2.Area(); } }
ART原艺美学
慕粉4075985
相关分类