慕粉7269117
2018-09-14 16:12
package com.imooc; public abstract class Shape{ public abstract double perimeter(); public abstract double area(); } _______________________________________________________________ package com.imooc; public class Circle extends Shape{ double r = 3.4; @Override public double perimeter(){ retrun Math.PI * 2 * r } @Override public double area(){ return Math.PI * r * r; } } _______________________________________________________________ package com.imooc; public class initial{ public static void main(String[] args){ Shape cc = new Circle(); Shape rt = new Rectangle(); System.out.println("圆的面积为:"+cc.area()); System.out.println("圆的周长为:"+cc.perimeter()); } }
多了一句代码,Shape rt = new Rectangle();
多了一句代码,Shape rt = new Rectangle();
长方形的没写出来
Java入门第二季 升级版
530655 学习 · 6091 问题
相似问题