演示一些静态嵌套类 : 匿名内部类 « 类定义 « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » 类定义 » 匿名内部类 
5. 15. 14. 演示一些静态嵌套类
/*
 *     file: DoubleNestedClassDemo.java
 *  package: oreilly.hcj.nested
 *
 * This software is granted under the terms of the Common Public License,
 * CPL, which may be found at the following URL:
 * http://www-124.ibm.com/developerworks/oss/CPLv1.0.htm
 *
 * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
 * All Rights are Reserved by the various authors.
 *
########## DO NOT EDIT ABOVE THIS LINE ########## */
/*
 *     file: DoubleNestedClass.java
 *  package: oreilly.hcj.nested
 *
 * This software is granted under the terms of the Common Public License,
 * CPL, which may be found at the following URL:
 * http://www-124.ibm.com/developerworks/oss/CPLv1.0.htm
 *
 * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
 * All Rights are Reserved by the various authors.
 *
########## DO NOT EDIT ABOVE THIS LINE ########## */


/**  
 * Demonstration of some static nested classes.
 *
 @author <a href=mailto:kraythe@arcor.de>Robert Simmons jr. (kraythe)</a>
 @version $Revision: 1.3 $
 */
 class DoubleNestedClass {
  /** Holds the name. */
  private static final String name = "Robert";

  /** Holds the company. */
  private static String company = "O'Reilly";

  /** Holds a value. */
  private int value = 5;

  /** 
   * Getter for the property company.
   *
   @return The current company.
   */
  public static String getCompany() {
    return company;
  }

  /** 
   * Getter for the variable name.
   *
   @return The current name.
   */
  public static String getName() {
    return name;
  }

  /** 
   * Getter for the variable company.
   *
   @return the current company.
   */
  public int getValue() {
    return value;
  }

  /**  
   * A demo nested static class.
   *
   @author <a href=mailto:kraythe@arcor.de>Robert Simmons jr. (kraythe)</a>
   @version $Revision: 1.3 $
   */
  public static class SomeClass {
    /** Name of the book. */
    private static final String book = "Hardcore Java";

    /** 
     * a demo method.
     */
    public void someMethod() {
      System.out.println("In SomeClass.someMethod()");
      System.out.println(company);
      System.out.println(name);
      // System.out.println(value); // <= Compiler error
    }

    /**  
     * A demo nested static class.
     *
     @author <a href=mailto:kraythe@arcor.de>Robert Simmons jr. (kraythe)</a>
     @version $Revision: 1.3 $
     */
    public static class SomeOtherClass {
      /** 
       * a demo method.
       */
      public void someMethod() {
        System.out.println("In SomeOtherClass.someMethod()");
        System.out.println(company);
        System.out.println(book);
      }
    }
  }
}

/* ########## End of File ########## */


/**  
 * Demonstrates Static nested Classes.
 *
 @author <a href=mailto:kraythe@arcor.de>Robert Simmons jr. (kraythe)</a>
 @version $Revision: 1.3 $
 */
public class DoubleNestedClassDemo {
  /** 
   * Main method.
   *
   @param args Command line arguments.
   */
  public static void main(final String[] args) {
    DoubleNestedClass.SomeClass.SomeOtherClass obj =
      new DoubleNestedClass.SomeClass.SomeOtherClass();
    obj.someMethod();
  }
}

/* ########## End of File ########## */
5. 15. 匿名内部类
5. 15. 1. 内部类
5. 15. 2. 定义一个内部类
5. 15. 3. 使用匿名内部类
5. 15. 4. 建立匿名内部类原地
5. 15. 5. Anonymous inner class cannot have a named constructor, only an instance initializer
5. 15. 6. 创建构造函数一个匿名内部类
5. 15. 7. Using 'instance initialization' to perform construction on an anonymous inner class
5. 15. 8. Argument must be final to use inside anonymous inner class
5. 15. 9. 方法,返回一个匿名内部类
5. 15. 10. An anonymous inner class that calls the base-class constructor
5. 15. 11. 匿名内部类执行初始化
5. 15. 12. 表明方法范围的内部类
5. 15. 13. 使用内部类
5. 15. 14. 演示一些静态嵌套类
5. 15. 15. 从外面访问内部类
5. 15. 16. Accessing its enclosing instance from an inner class
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.