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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:03:16+00:00 2026-06-15T12:03:16+00:00

I have a class, Action, that has a method called doAction(). This method exists

  • 0

I have a class, Action, that has a method called doAction(). This method exists solely to be overwritten for each new action that I add to an action list called allActions.

public void doAction() {
    System.out.println("Overload this method.");
} 

The list of actions is being stored in the following list:

public static List<Action> allActions = new ArrayList<Action>();

and added to this list with calls like the following:

allActions.add(
    new Action(id){
        public void doAction(Word w1, Word w2) {
            //perform some action
        }
    }
);

But this code isn’t working for me. When I try to access an overwritten doAction() method from the allActions list, it just performs the default method.

I suspect that the problem is that allActions is a list of Action objects, so perhaps the type is being changed away from the anonymous class when it is being added to the list, and reverting to the default method.

Any ideas on how to maintain a list of different anonymous versions of the Action class? I want to be able to call these different doAction() methods based on the id given to the actions.

By the way, this is my first time encountering anonymous classes. I think I understand the concept, but actually using them is another story.

  • 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-15T12:03:17+00:00Added an answer on June 15, 2026 at 12:03 pm

    You actually are overloading the method doAction(). But I suspect you may have confused the words overload and override.

    To overload a method, you use a different quantity or type of parameters. This allows the same method to do different things depending how you call it (i.e. with what parameters).

    Information on overloading

    To override a method, you use the same quantity and type of parameters, and you are required to return the same type as the overridden (super) method. This allows the same method to do different things depending where you call it (i.e. from a superclass or a subclass).

    Information on overriding

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

Sidebar

Related Questions

I have a class that has an Action<string> called DisplayData ; In various points
I have a model, smth like this: class Action(models.Model): def can_be_applied(self, user): #whatever return
So I have this controller called Cars, and it has: namespace MySite.Controllers { public
I have a model called Subscription that has a unique index on the fields
I Have an Enum Called ActionStatus that has 2 possible values open=0 and closed
I have a class that extends Thread. This thread when running spends most of
I have two classes called Lecturer and Course. My Lecturer class has a List
I have a class that has a number of methods that follow the below
i have a main Activity called Main which has onActivityResult Method. protected void onActivityResult(int
I have a controller action that calls a model method which generates a serialized

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.