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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:05:27+00:00 2026-05-13T18:05:27+00:00

I am trying to create a class. Let’s call it Questionnaire. In Questionnaire, I

  • 0

I am trying to create a class. Let’s call it Questionnaire. In Questionnaire, I want to instantiate a number of classes called Question. The constructor for Questionnaire accepts a string array of words, and for each word, there should be a Question class to accept it as an argument for its constructor. In other words, for every string that is passed as an argument, I want to create a Question.

I need to be able to put Questionnaire within a bigger class and still call the methods of the Question classes. The size of the array passed to Questionnaire varies as well. I don’t know how I can put multiple classes within another class when I don’t know how many classes there will be, and how to reference them from an outer class. If the array was a fixed length I’d just create Questions as question1, question2, question3… but since this is not the case I am not sure anymore. I do know there is a maximum number of Question classes I want to create though.

edit: I’m using J2ME CDLC 1.1 MIDP 2.0 for this (it’s part of a mobile phone app) so my solutions are constrained by what it offers.

  • 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-13T18:05:27+00:00Added an answer on May 13, 2026 at 6:05 pm

    You don’t want to have a separate variable per question – use a List<Question> to have one variable which refers to a collection of questions:

    public class Questionnaire
    {
        private final List<Question> questions;
    
        public Questionnaire(String[] words)
        {
            questions = new ArrayList<Question>();
            for (String word : words)
            {
                questions.add(new Question(word));
            }
        }
    
        // Use questions here
    }
    

    EDIT: If you’re in an environment without generics, you could use the non-generic form, like this:

        private final List questions;
    
        public Questionnaire(String[] words)
        {
            questions = new ArrayList();
            for (String word : words)
            {
                questions.add(new Question(word));
            }
        }
    

    or like this if you don’t have List/ArrayList:

        private final Vector questions;
    
        public Questionnaire(String[] words)
        {
            questions = new Vector();
            for (String word : words)
            {
                questions.add(new Question(word));
            }
        }
    

    In either case you’ll need to cast on every access. Alternatively, you could use an array:

        private final Question[] questions;
    
        public Questionnaire(String[] words)
        {
            questions = new Question[words.length];
            for (int i = 0; i < words.length; i++)
            {
                questions[i] = new Question(word);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 302k
  • Answers 302k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If AdwizaRepeatBox, AdwizaRepeatBox, AdwizaSlavebox and other don't extend single class… May 13, 2026 at 8:29 pm
  • Editorial Team
    Editorial Team added an answer Seems you should really need more freeform structure than a… May 13, 2026 at 8:29 pm
  • Editorial Team
    Editorial Team added an answer You want a "Data Source", specifically an "object data source".… May 13, 2026 at 8:29 pm

Related Questions

This is my project setup: In visual studio I have a solution with a
C#, .net 3.5 I am trying to create a base class that has a
Preamble So, this question has already been answered, but as it was my first
I would like to create a very simple image gallery. I am trying to
I am trying to organize my JavaScript. What I would like to do is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.