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

📄 pair.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package examples.cloning;

/** An example class used to demonstrate how to
  * enable cloning for a class without fields that
  * contain object references..
  */
public class Pair implements Cloneable {

   private int a, b;

   /** Class constructor method
     * @param a Initial value for the first field
     * @param b Initial value for the second field
     */
   public Pair( int initA, int initB ) {
      a = initA;
      b = initB;
   }

   /** Convert object to String representation
     * @return The value of the array as a String
     */
   public String toString() {
      return "( " + a + ", " + b + " )";
   }

   /** The test method for the class
     * @param args Not used
     * @exception CloneNotSupportedException
     *            If clone not supported by
     *            inherited clone method
     */
   public static void main( String[] args ) 
         throws CloneNotSupportedException {
      Pair x = new Pair( 5, 6 );
      System.out.println( x );

      Pair y = (Pair) x.clone();
      System.out.println( y );
   }
}

⌨️ 快捷键说明

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