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

  • SEARCH
  • Home
  • 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 8989113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:10:27+00:00 2026-06-15T22:10:27+00:00

I have a class component abstract class Component{ private componentType m_type; public Component(componentType type)

  • 0

I have a class component

abstract class Component{
    private componentType m_type;

    public Component(componentType type)
    {
        m_type = type;
    }
}

and 2 subclasses

class AmplifierComponent extends Component{
    public AmplifierComponent()
    {
        super(componentType.Amp);
        System.out.print(this.m_type);
    }
}

class AttenuatorComponent extends Component{
    public AttenuatorComponent()
    {
        super(componentType.Att);
        System.out.print(this.m_type);
    }
}

my problems are:
1.i can’t instantiate any kind of component because m_type isn’t visible(what that means?)
2.i need to make an array of all the components the user has insert to the chain. i can’t manage to create an array of Component class.

can someone help me with the design?
or with some workarounds?

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-15T22:10:28+00:00Added an answer on June 15, 2026 at 10:10 pm

    I don’t understand why you need the type member. This looks redundant. You can instead simply do:

    abstract class Component{
    }
    
    class AttenuatorComponent extends Component{
        public AttenuatorComponent() {
           // calls the default super constructor
        }
    }
    

    and rely on polymorphism for your classes to behave appropriately. Having a type member to identify a hierarchy type is unnecessary when you’ve declared the corresponding classes. If you do have a member variable that is required to be visible in subclasses but not by clients, then you can make it protected rather than private.

    Component could be an interface if there’s no functionality/data associated with it.

    Your array declaration would look like

    Component[] components = new Component[20];
    components[0] = new AttenuatorComponent();
    

    Polymorphism would mean that you can iterate through this array of components, calling appropriate methods declared on (but not necessarily implemented by) the Component, and the suitable subclass methods would be called.

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

Sidebar

Related Questions

I have next structure: @Component public abstract class HuginJob extends QuartzJobBean {...} @Component(CisxJob) public
I have two spring beans as follows: @Component(A) @Scope(prototype) public class A extends TimerTask
Let's say I have: public class Components<T> extends TupleList<Class<T>, String> { private static final
I have a User class: @Component @Scope(session) public class User { private String username;
I have: @Component class MyDecorator{ private Cache cache; /* some wrapped methods like get
I have these three classes: Command: package pack; public abstract class Command impements java.io.Serializable
I have Generic list holding root objects means I have: public class Component {
I have this class: @Component @Scope(session) @Entity @Table(name = users) public class User {
To start, some classes: public abstract class Component { GenericSystem mySystem; public Component() {
i have the following classes and mappings abstract class BaseClass { public virtual int

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.