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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:14:18+00:00 2026-05-31T03:14:18+00:00

I created a class in a file called Pq which is an object having

  • 0

I created a class in a file called Pq which is an object having Strings like this

public class PQ {
    String ec;
    String com;
    String ai[3];
    String answers[3];
 }

Now I want to make an array of this object of length 10.
Then fill each of the individual elements like ec,com with data as per my requirement with a for loop like

for(i=0;i<10;i++)
    pq.ec=25;

How to do this?
I also want to fill ai,answers. How to access those elements
I tried ArrayList but I am able to add the whole object but unable to add individual items
Please help me out

  • 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-31T03:14:19+00:00Added an answer on May 31, 2026 at 3:14 am

    In your PQ class define getters and setters to manipulate fields of your objects safely conforming to the principle of encapsulation.

    public String getEc ()
    {
        return ec;
    }
    
    public void setEc ( String ec )
    {
        this.ec = ec;
    }
    
    public String getCom ()
    {
        return com;
    }
    
    public void setCom ( String com )
    {
        this.com = com;
    }
    
    public String [] getAi ()
    {
        return ai;
    }
    
    public void setAi ( String [] ai )
    {
        this.ai = ai;
    }
    
    public String [] getAnswers ()
    {
        return answers;
    }
    
    public void setAnswers ( String [] answers )
    {
        this.answers = answers;
    }
    

    To populate an array of PQ objects use a code similar to this:

    PQ [] objects = new PQ [ 10 ];
    
    for ( int i = 0; i < objects.length; i++ )
    {
        objects [ i ].setEc( "your ec" );
        objects [ i ].setCom( "your com" );
        objects [ i ].setAi( new String [] {"fill the string array"} );
        objects [ i ].setAnswers( new String [] {"fill the string array"} );
    }
    

    Note that you can fill each field of individual objects by using the appropriate setter method and valid argument(s).

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

Sidebar

Related Questions

I created a class that's something like this: public class MovieTheaterList { public DateTime
I've created an object called loginInterface in flex builder. When this object is initialized
I have created a Class Library (called as GNGEngine.dll) which performs some image processing
I have created a C# class file by using a XSD-file as an input.
i am using a WSDL file to create a the proxy class file, this
I've created class that takes Exception type in constructor private readonly Exception _exception; public
First of all i created a class called PrivateShirt1 and called a private field
I've got a template class called w32file which works with both wchar_t and char.
I have a base class called Geometry from which there exists a subclass Sphere
class MyThing { protected HashMap<String,Object> fields; protected MyThing(HashMap<String,Object> newFields){ fields.putAll(newFields); } protected Object get(String

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.