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 4 of 4

Thread: Anonymous class Example : What's wrong with my code?? :(

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    9
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Anonymous class Example : What's wrong with my code?? :(

    package test;
    public class Anonymous{

    public class Popcorn{
    public void pop(){
    System.out.println("Popcorn pops");
    }
    }


    public static void main(String args[]){

    Popcorn p = new Popcorn(){
    public void pop(){
    System.out.println("Cooks popcorn");
    }
    };
    p.pop();
    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Anonymous class Example : What's wrong with my code?? :(

    What's wrong with my code?
    It's not properly formatted for displaying on the forum
    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    If you are getting errors, please copy and paste the full text here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    9
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Anonymous class Example : What's wrong with my code?? :(

    <
    package test;
    public class Anonymous{
     
    public class Popcorn{
    public void pop(){
    System.out.println("Popcorn pops");
    }
    }
     
     
    public static void main(String args[]){
     
    Popcorn p = new Popcorn(){
    public void pop(){
    System.out.println("Cooks popcorn");
    }
    };
    p.pop();
    }
     
    }
    >

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Anonymous class Example : What's wrong with my code?? :(

    What happened to the indentation formatting of the code? All the statements start in column one. There should be indentation of source lines for each level of nesting of the logic. For example:
       public void pop(){
          System.out.println("Popcorn pops");
       }
    If you are getting errors, please copy and paste the full text here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. This Code worked on a separate class but does not work on another class
    By titowinky in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 25th, 2012, 08:48 AM
  2. Replies: 6
    Last Post: July 21st, 2011, 07:45 AM
  3. What is Wrong With My Exception Class Code?
    By Allicat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 5th, 2011, 10:09 AM
  4. What is wrong with this code class not found
    By newbieJava in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 19th, 2011, 06:39 PM
  5. Anonymous is here
    By anonymous in forum Member Introductions
    Replies: 2
    Last Post: March 1st, 2010, 03:10 AM