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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:45:22+00:00 2026-06-13T10:45:22+00:00

I am looking for help with having multiple different types of system accessed within

  • 0

I am looking for help with having multiple different types of system accessed within java as if they are the same.

For example, I have the classes

private class SystemA{

    public void in(boolean input){
      //do x;
    }
    public boolean out(){
      //return x;
    }
}

Say I want to have an ArrayList of different systems. These systems all implement the functions in and out like SystemA does, but they will be different objects all with different internal architectures.

I would like to for example iterate through the aformentioned arraylist, calling out() on all of the objects – how can I:

Store multiple different object types.
Ensure that I can call the in and out functions on the object in the arraylist, not needing to worry that the object is one specific type or another.

  • 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-13T10:45:23+00:00Added an answer on June 13, 2026 at 10:45 am

    Let your system classes implement a new MySystem interface:

    public interface MySystem {
        void in(boolean input);
        boolean out();
    }
    

    E.g.:

    private class SystemA implements MySystem {
        @Override
        public void in(boolean input) { ... }
        @Override
        public boolean out() { ... }
    }
    

    Your ArrayList will then look like any of these:

    List<MySystem> list = new ArrayList<MySystem>();
    List<? extends MySystem> list = someFactoryMethod();
    

    I suggest reading the Java tutorial “What Is an Interface?” for more details. Also, read up on “subtype polymorphism” in general.

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

Sidebar

Related Questions

looking for some help with images referenced within the stylesheet. I have no problems
LINQ gurus, I am looking for help to write a query... I have a
I am looking to create a distributed framework in Java and need some help
i am looking for help on an up down voting system. at the moment
I am new to Java and looking for some help with Java's Scanner class.
Looking for some help on a problem Im having sorry if this question has
I am looking for help with the database scheme, not the actual cloud itself.
I am looking for help in determining if the class model that I am
I'm looking for help with my query below. which is never returning anything for
I'm looking for help using sum() in my SQL query: SELECT links.id, count(DISTINCT stats.id)

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.