Results 1 to 6 of 6

Thread: What does anonymous class mean in java?

  1. #1
    Join Date
    Dec 2009
    Posts
    38

    What does anonymous class mean in java?

    Hello Guys,

    I need help to aware about the "anonymous class" in java programming. I know what is simple java class and it's declaration. But the "anonymous class" concept is new for me. I wonder if you let me know something regarding the anonymous class of java. It will be great you provide suitable example for anonymous class. I am waiting for your reply.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: What does anonymous class mean in java?

    An anonymous class can have constructors because the name of a constructor must be identical to that class (and it did not name). Instead, the design parameters are given to the constructor of the super class. In particular, each time an inner class implements an interface, it can not have design parameters. It should nevertheless always supply the parentheses, as in this example:
    Code:
    new TypeInterface1() (Attributes & methods of anonymous inner class)

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What does anonymous class mean in java?

    Hi,

    I following example the method "lancerMinuteur1 ()" create "Timer" in the anonymous class:

    Code:
    private void lancerMinuteur1(Final boolean beep) 
    {
      new ActionListener()
     {
         private Timer TimerN = new Timer(1000, this);
         { TimerN.home(); }
         Public void actionPerformed(ActionEvent e)
       {
            time.setText(DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date()));
            if (beep) Toolkit.getDefaultToolkit().beep();
         }
      }; 
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: What does anonymous class mean in java?

    In java programming the class can be of anonymous type. It means "anonymous classes " can be declared without an identifier. In some situation this concept is very useful, such as when we replace a name of class with a "typedef name", as shown in the following:
    typedef struct
    {
    unsigned Q;

    unsigned W;

    } POINT;

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: What does anonymous class mean in java?

    The use of anonymous classes generally leads to codes barely legible. We reserve the highly case individuals where the definition of the anonymous class is brief. The anonymous class is particularly interesting in the definition of event Listeners. The anonymous class can access the instance as well as the static variables. It are also essential when we want a reference to member of the class to appear as though it were not contained in a separate class.

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: What does anonymous class mean in java?

    Hi friend,

    The anonymous class of java comprises some restriction, which are as follows:
    • Anonymous class can't be returned as return values from functions.
    • Anonymous class can't have a Destructor or Constructor .
    • Anonymous class can't be passed as an arguments to functions.

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. JRadioButton class of java
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 08:27 AM
  3. StringTokenizer class of java
    By Mithun Seth in forum Software Development
    Replies: 5
    Last Post: 10-02-2010, 01:12 PM
  4. explain class in java
    By GlassFish in forum Software Development
    Replies: 3
    Last Post: 03-11-2009, 09:59 AM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,718,540,108.91492 seconds with 17 queries