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

📄 outer.java

📁 java源程序 对初学者有很大的帮助 从简单到复杂
💻 JAVA
字号:
//********************************************************************
//  Outer.java       Author: Lewis/Loftus
//
//  Represents a class that encapsulates an inner class.
//********************************************************************

public class Outer
{
   private int num;
   private Inner in1, in2;

   //-----------------------------------------------------------------
   //  Sets up this object, initializing one int and two objects
   //  created from the inner class.
   //-----------------------------------------------------------------
   public Outer()
   {
     num = 9876;
     in1 = new Inner ("Half of the problem is 90% mental.");
     in2 = new Inner ("Another deadline. Another miracle.");
   }

   //-----------------------------------------------------------------
   //  Changes the messages in the Inner objects (directly).
   //-----------------------------------------------------------------
   public void changeMessages()
   {
      in1.message = "Life is uncertain. Eat dessert first.";
      in2.message = "One seventh of your life is spent on Mondays.";
   }

   //-----------------------------------------------------------------
   //  Returns this object as a string.
   //-----------------------------------------------------------------
   public String toString()
   {
      return in1 + "\n" + in2;
   }

   //*****************************************************************
   //  Represents an inner class. 
   //*****************************************************************
   private class Inner
   {
      public String message;

      //--------------------------------------------------------------
      //  Sets up this Inner object with the specified string.
      //--------------------------------------------------------------
      public Inner (String str)
      {
         message = str;
      }

      //--------------------------------------------------------------
      //  Returns this object as a string, including a value from
      //  the outer class.
      //--------------------------------------------------------------
      public String toString()
      {
         num++;
         return message + "\nOuter num = " + num;
      }
   }
}

⌨️ 快捷键说明

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