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 8557833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:39:52+00:00 2026-06-11T15:39:52+00:00

I am learning java swing and came across the concept of anonymous inner class.

  • 0

I am learning java swing and came across the concept of anonymous inner class. After studying a bit at this link, I feel that an anonymous inner class must always extend some other class since the method in which it gets passed as a parameter is predefined. At most, if a method accepts Object instances as parameter, only then we can create an anonymous independent inner class. I just seek your opinion whether I am right. It would be helpful if you could provide some example.
Thanks in advance.

  • 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-11T15:39:54+00:00Added an answer on June 11, 2026 at 3:39 pm

    Creating an anonymous inner class without extending anything would basically mean that you’d have no way of talking to it.

    You need to extend a class or implement an interface just to give your object known methods to talk to, for example;

    myButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
            // do something here.
        }
    });
    

    The only way to talk to an instance of that object is through the known ActionListener methods (which happens to be exactly the methods addActionListener needs), any other methods you’d add would only be accessible inside the object itself. If you didn’t have to extend/implement anything, no methods would be externally accessible at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a Java newbie learning Swing... Hopefully this is really simple. I've created a
I am learning Java with Swing and I have some problems with using JTextField
Hi I have been learning Java Swing for creating a chess game to practice
I'm learning event-driven programming by Java now, but most materials are about swing. I
I am learning Java using Eclipse - started a project with javax.swing and could
I am starting to learn Java a little after long time. And learning Netbeans
I am learning java swing from the Dive Log tutorial. An object has been
I am learning java swing. There is an editable JComboBox for selecting different depths
I am learning java swing. The code below is a catch block which handles
Here is the code of my Layout class. import java.awt.event.*; import java.awt.*; import javax.swing.*;

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.