⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 override.java

📁 是一本比较好的JAVA学习书
💻 JAVA
字号:
class Point2D { //定义二维的点
  protected int x, y;
  public Point2D() {
    this.x=0;
    this.y=0;}
  public Point2D(int x, int y) {
    this.x = x;
    this.y = y;
  }}
//定义三维的点,继承二维
class Point3D extends Point2D {
  protected int z;
  public Point3D(int x, int y) {
    this(x, y, 0);
  }
  public Point3D(int x, int y, int z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }}
//定义二维的位置
class Position2D {
  Point2D location;
  public Position2D() {
    this.location = new Point2D();
  }
  public Position2D(int x, int y) {
    this.location = new Point2D(x, y);
  }
  public Point2D getLocation() {
    return location;
  }}
//定义三维的位置,继承二维的位置
class Position3D extends Position2D {
  Point3D location; //在这里已经变成Point3D的类型了
  public Position3D(int x, int y, int z) {
    this.location = new Point3D(x, y, z);
  }
  @Override  //注释是重写方法
  public Point3D getLocation() {
    return location; //返回是子类的类型而不是原来的类型了
  }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -