ex4.java
来自「讲述各种各样的java初始编程 了解编程」· Java 代码 · 共 78 行
JAVA
78 行
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package chenchao3;/** * * @author williechen */public class Ex4 {}interface Centered { void setCenter(double x, double y); double getCenterX(); double getCenterY();}class CenteredRectangle extends Rectangle implements Centered { // New instance fields private double cx, cy; // A constructor public CenteredRectangle(double cx, double cy, double w, double h) { super(w, h); this.cx = cx; this.cy = cy; } // We inherit all the methods of Rectangle but must // provide implementations of all the Centered methods. public void setCenter(double x, double y) { cx = x; cy = y; } public double getCenterX() { return cx; } public double getCenterY() { return cy; }}class CenteredCircle extends Circle implements Centered { // New instance fields private double cx, cy; // A constructor public CenteredCircle(double cx, double cy, double r) { super(r); this.cx = cx; this.cy = cy; } // We inherit all the methods of Rectangle but must // provide implementations of all the Centered methods. public void setCenter(double x, double y) { cx = x; cy = y; } public double getCenterX() { return cx; } public double getCenterY() { return cy; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?