package com.imooc; public abstract class Shape { public abstract void Circum(); public abstract void Area(); } public class Rectangle extends Shape { float a,b,area1,circum; public void init(){ a=10f; b=9f; } public void Area(){ area1=a*b; System.out.println("矩形的面积为"+area1); } public void Circum(){ circum=2*(a+b); System.out.println("矩形的周长为"+circum); } } public class Circle extends Shape { public float r; public double Arae1,Circum1; public void init(){ r=5f; } @Override public void Area() { // TODO Auto-generated method stub Arae1=3.14*r*r; System.out.println("圆的面积是"+Arae1); } @Override public void Circum() { // TODO Auto-generated method stub Circum1=3.14*2*r; System.out.println("圆的周长是"+Circum1); } } public class Initail { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Shape R1=new Rectangle(); Shape C2=new Circle(); R1.Area(); R1.Circum(); C2.Area(); C2.Circum(); }
矩形的面积为0.0
矩形的周长为0.0
圆的面积是0.0
圆的周长是0.0
天启之魂
siiv
相关分类