Demonstrate an inner class. : Anonymous inner class « Class Definition « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Class Definition » Anonymous inner class 
5. 15. 1. Demonstrate an inner class.
class Outer {
  int outer_x = 100;
   
  void test() {
    Inner inner = new Inner();
    inner.display();
  }
   
  // this is an inner class
  class Inner {
    void display() {
      System.out.println("display: outer_x = " + outer_x);
    }
  }
}
   
class InnerClassDemo {
  public static void main(String args[]) {
    Outer outer = new Outer();
    outer.test();
  }
}
5. 15. Anonymous inner class
5. 15. 1. Demonstrate an inner class.
5. 15. 2. Define an inner class within a for loop.
5. 15. 3. Use anonymous inner classes
5. 15. 4. Building the anonymous inner class in-place
5. 15. 5. Anonymous inner class cannot have a named constructor, only an instance initializer
5. 15. 6. Creating a constructor for an anonymous inner class
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. A method that returns an anonymous inner class
5. 15. 10. An anonymous inner class that calls the base-class constructor
5. 15. 11. An anonymous inner class that performs initialization
5. 15. 12. Demonstrates method-scoped inner classes
5. 15. 13. Demonstrates anonymous classes
5. 15. 14. Demonstration of some static nested classes
5. 15. 15. Access inner class from outside
5. 15. 16. Accessing its enclosing instance from an inner class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.