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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:34:29+00:00 2026-05-27T14:34:29+00:00

I am just working on my knowledge of ArrayLists and have a question. I

  • 0

I am just working on my knowledge of ArrayLists and have a question.

I have 4 classes, a person superclass, employee subclass, pupil subclass and a manager subclass of employee.

What I don’t understand is how I can use the method m.setBonus on the people ArrayList. I know I can split the objects into separate arrays but I’m not sure if that is the answer.

I am currently getting an error on the Manager m : manager part because there is no reference for manager I assume.

I currently have this code in my test class

public static void main(String[] args){

ArrayList<Person> people = new ArrayList<Person>();

people.add(new Employee("Tom", 4000, 1990, 3, 10));
people.add(new Pupil("Dick", "Comp Sci"));
people.add(new Employee("Harry", 4000, 1990, 3, 10));
people.add(new Manager ("Dan", 5000, 1990, 10, 1));

for (Manager m : manager)
{
    m.setBonus(5000);
}

for (Person p : people){

    System.out.println(p.getDetails());
}

}

}

I am sorry if this is a really simple thing. I just can’t find anything on the net.

Cheers

  • 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-05-27T14:34:29+00:00Added an answer on May 27, 2026 at 2:34 pm

    The manager arrayList does not exist, instead do the check in your existing Person loop.

    public static void main(String[] args) {
        ArrayList<Person> people = new ArrayList<Person>();
    
        people.add(new Employee("Tom", 4000, 1990, 3, 10));
        people.add(new Pupil("Dick", "Comp Sci"));
        people.add(new Employee("Harry", 4000, 1990, 3, 10));
        people.add(new Manager ("Dan", 5000, 1990, 10, 1));
    
        // manager arrayList does not exist
        //for (Manager m : manager)
        //{
        //  m.setBonus(5000);
        //}
    
    
        for (Person p : people){
            //Do this instead
            if (p instanceof Manager) {
                ((Manager) p).setBonus(5000);
            }
    
            System.out.println(p.getDetails());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started working with Mercurial a few days ago and there's something I don't
I just started working on a website that will help people understand what rappers
I have just started working with a new company in a very small IT
I'm learning JSP and have a good working knowledge of PHP and MVC frameworks.
I just started working at a company that doesn't have any kind of source
I have little knowledge with the iPhone SKD (don't even know what code it
I have little working knowledge of python. I know that there is something called
I'm not an advanced user of CSS, but I have a decent working knowledge
I have just started studying Android, I have limited java knowledge but am semi
I am working on this project just trying to keep up my c++ knowledge.

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.