Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: quick question - new keyword

  1. #1
    Member
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    10
    Thanked 3 Times in 3 Posts

    Default quick question - new keyword

    hi all, quick question here. dont recall seeing this in suns java tutorial.


    SwingUtilities.invokeLater(new Runnable() [B]{
    public void run() {
    new SwingDemo();
    }
    }[/B]);

    What exactly happens with the block following new's call to the constructor? Is this some sort of way of overriding the class' default implementation of the method "on the spot"? Just looking for a quick explanation for the syntax rule behind the bold block above.


  2. #2
    Member
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    10
    Thanked 3 Times in 3 Posts

    Default Re: quick question - new keyword

    Whoops, I wasn't aware that Runnable was an interface that defined only one method. This leads me to another question:

    What happens when you try to instantiate an interface? Does it create an Object object which implements the interface?

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: quick question - new keyword

    This is what's called an "anonymous class". basically, it's a class that has know name. It can be created from any abstract class or interface.

    You cannot directly create an abstract class or an interface. You must have either a class that extends it or implements it (respectively for class or interface).

  4. The Following User Says Thank You to helloworld922 For This Useful Post:

    bbr201 (July 19th, 2010)

Similar Threads

  1. Quick Question about Mergesort
    By Shadow703793 in forum Algorithms & Recursion
    Replies: 4
    Last Post: March 4th, 2010, 05:48 PM
  2. Quick JComboBox Event Question
    By -tr in forum AWT / Java Swing
    Replies: 2
    Last Post: December 12th, 2009, 05:35 PM
  3. keyword Extends
    By chronoz13 in forum Object Oriented Programming
    Replies: 3
    Last Post: November 27th, 2009, 07:30 AM
  4. Quick binary tree question.
    By Sinensis in forum Java Theory & Questions
    Replies: 1
    Last Post: November 15th, 2009, 09:28 PM
  5. How to highlight search keyword in text?
    By Mohd in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: February 1st, 2009, 06:35 AM