title: java run method in custom class
body: <p>So I am making an application with custom menus. I have two types of classes for this, the MenuContainer class, and MenuOption class. The MenuContainer decides the size, location and align of the menu, and the MenuOption decides string to be show, font, color and so on. I also wanted to add a piece of code to each MenuOption, the code decides what is to happen when the MenuOption is clicked. So each MenuOption has its own unique code that is set when creating a new MenuOption. How do I do this? I am hoping something like this may work:</p>
  
  <pre><code>MenuOption option1 = new MenuOption("Option1",font,color) {
  
      public void run() {
  
          //code to be executed
  
      }
  
  };
  
  option1.run();  //running the code
  </code></pre>
  
  <p>I don't know if this is asked often, but I searched and found nothing. </p>