文件名称:类与对象、接口
文件大小:16KB
文件格式:DOCX
更新时间:2020-12-31 15:00:56
类、接口
package shiyan4; public interface Shape { public abstract void getArea(); public abstract void draw(); } package shiyan4; import Shape.*; class Circle implements Shape { private double r; public void Cricle(double r)//以半径r为参数构造一个圆 { this.r = r; } public double getArea(double r) { return r*r*Math.PI; } public void draw() { System.out.println("I am a circle"); } @Override public void getArea() { // TODO Auto-generated method stub } } class Rectangle implements Shape { private double x; private double y; public Rectangle(double x,double y) { this.x = x; this.y = y; } public double getArea(double x,double y) { return x*y; } public void draw() { System.out.println("I am a rectangle"); } @Override public void getArea() { // TODO Auto-generated method stub } } public class fangfa { public static void main(String[] args) { Circle c1 = new Circle(); Rectangle r1 = new Rectangle(2.0,3.0); System.out.println("圆形的面积是"+c1.getArea(1.0)); c1.draw(); System.out.println("矩形的面积是"+r1.getArea(2.0,3.0)); r1.draw(); } }