hasxy2.java

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

JAVA
50
字号
package examples.inheritance;

/** An example Java subclass used to demonstrate
  * inheritance concepts
  */
public class HasXY2 extends HasX2 {

   private int y;

   /** Method to set the object's value
     * @param inputY The field's new value
     */
   public void setY( int inputY ) {
      y = inputY;
   }

   /** Method to get the object's value
     * @return The value of the field
     */
   public int getY() {
      return y;
   }

   /** Method to write the value of Y to
     * <code>System.out</code>.
     */
   public void showY() {
      System.out.println( y );
   }

   /** Method to write the value of X to
     * <code>System.out</code>. This is required
     * because this method is an abstract
     * method in the superclass.
     */
   public void showX() {
      System.out.println( getX() );
   }

   /** The test method for the class
     * @param args Not used
     */
   public static void main( String[] args ) {
      HasXY2 obj = new HasXY2();   
      obj.setY( 20 );
      obj.setX( 10 );
      obj.showY();
      obj.showX();
   }
}

⌨️ 快捷键说明

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