location3d.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 27 行

JAVA
27
字号
package examples.errors;
import examples.inheritance.Location2D;
/** A class intended to create an error
  */
public class Location3D extends Location2D {
   protected int z;
   public Location3D( int initX, int initY,
                      int initZ ) {
      x = initX;
      y = initY;
      z = initZ;
   }
   public static void show2D( Location2D p2 ) {
      // The line below results in a compiler error
      // because the data members are not accessible
      System.out.println( "(" + p2.x + ", "
                          + p2.y + ")" );
   }
   public static void show3D( Location3D p3 ) {
      System.out.println( "(" + p3.x + ", " + p3.y
                          + ", " + p3.z + ")" );
   }
   static public void main( String[] args ) {
      Location3D a = new Location3D( 1, 2, 3 );
      Location3D.show3D( a );
   }
}

⌨️ 快捷键说明

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