Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:10:36+00:00 2026-06-03T03:10:36+00:00

If a class is a local inner class, does this mean that it is

  • 0

If a class is a local inner class, does this mean that it is inside a method of another class or does it mean that it is just defined in another method somewhere.

For example, in the code below, is the MenuListener considered an inner local class?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MenuDemo extends JFrame{
private Container c;
private ImageIcon[] images = new ImageIcon[5];
private JLabel picture;
private JPanel mainPanel;
private JMenuBar menuBar;
private JMenu menu;
private JMenuItem bird,cat,dog,rabbit,pig;

public MenuDemo() {
    super("Menu Demo");

    c = getContentPane();
    c.setLayout(new BorderLayout());

    mainPanel = new JPanel();

    // Store the animal pictures in an array.
    for (int i=0; i<5; i++){
        images[i] = new ImageIcon("image" + i + ".gif");
    }
    //Set up the picture label.
    picture = new JLabel(images[0]);
    picture.setPreferredSize(new Dimension(177,122));
    mainPanel.add(picture, BorderLayout.CENTER);
    c.add(mainPanel);
    buildMenuBar();
    this.setJMenuBar(menuBar);
    pack();
    setVisible(true);
}

private void buildMenuBar(){
    MenuListener listener = new MenuListener();
    menuBar = new JMenuBar();

    menu = new JMenu("Animals");
    menu.setMnemonic(KeyEvent.VK_A);
    menuBar.add(menu);

    bird = new JMenuItem("Bird", KeyEvent.VK_B);
    bird.addActionListener(listener);
    menu.add(bird);

    cat = new JMenuItem("Cat", KeyEvent.VK_C);
    cat.addActionListener(listener);
    menu.add(cat);

    dog = new JMenuItem("Dog", KeyEvent.VK_D);
    dog.addActionListener(listener);
    menu.add(dog);

    rabbit = new JMenuItem("Rabbit", KeyEvent.VK_R);
    rabbit.addActionListener(listener);
    menu.add(rabbit);

    pig = new JMenuItem("Pig", KeyEvent.VK_P);
    pig.addActionListener(listener);
    menu.add(pig);
}

private class MenuListener implements ActionListener {
    public void actionPerformed(ActionEvent e){
        if (e.getSource() == bird)
            picture.setIcon(images[0]);
        else if (e.getSource() == cat)
            picture.setIcon(images[1]);
        else if (e.getSource() == dog)
            picture.setIcon(images[2]);
        else if (e.getSource() == rabbit)
            picture.setIcon(images[3]);
        if (e.getSource() == pig)
            picture.setIcon(images[4]);
    }
}

public static void main(String[] args){
    MenuDemo m = new MenuDemo();
    m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:10:37+00:00Added an answer on June 3, 2026 at 3:10 am

    According to some official Oracle Java tutorial, a local inner class is a class that is defined in a code block rather than a part of another class’ definition. This means a class defined inside a method or in an initializer block.

    Following that definition, MenuListener is not a local inner class — it is just an inner class.

    So:

    public class Outer {
    
        public class Inner1 {
        }
    
        public static class Inner2 {
        }
    
        public void method(){
    
            class LocalInner{
            }
    
            LocalInner yesThisActuallyCompiles = new LocalInner();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to define a class method that has access to a local variable.
Are Local class, Inner class and Nested class mean same things in C++?
I am really confused with this one. Here's my code class inner { var
Possible Duplicates: Cannot refer to a non-final variable inside an inner class defined in
Possible Duplicate: Cannot refer to a non-final variable inside an inner class defined in
I have a class with static method which has a local static variable. I
If you look at the method below you will se a declared local class
In Java an anonymous inner class can refer to variables in it's local scope:
I have a class that I have serialized to disk on local users machines.
One of the legal modifiers you can use with method local inner classes is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.