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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:43:01+00:00 2026-05-26T13:43:01+00:00

I am working on my first Java program as a piece of homework. The

  • 0

I am working on my first Java program as a piece of homework. The task is to have a cataloging program to store and manipulate some products.

I have two classes, a catalog class and a product class. The product class stores data about my products (ID, Price, Color). The catalog list contains an array of products.

My code for the catalog goes something like this:

public class Catalog() 
    {
     static Product[] productList;

     Catalog () {
     productList = new Product[99];
     }

     populateCatalog {
     // Assign each item product in the product array an ID, Price & Color
     }
 }

The productList does not change throughout the program, therefore is it bad practice to add the code from the populateCatalog method to the constructor?

  • 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-26T13:43:01+00:00Added an answer on May 26, 2026 at 1:43 pm

    What you are doing in the constructor is fine. Another option is just to initialize the productList when you declare it, like

    static Product[] productList = new Product[99];

    However….

    you dont want productList to be static. As it stands right now, each Catalogue instance does NOT have a productList; the class as whole has one productList that it shares among all instances (which is what static means). It makes sense for each catalog to have its own product list right? So change your declaration to be

    private Product[] productList;

    That way every instance of Catalog will have its own productList.

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

Sidebar

Related Questions

I'm working on my first proper Clojure program--a chess game. I have the following:
I am working on a Java project using Netbeans for the first time. I
I am currently working on designing my first FPS game using JOGL. (Java bindings
I have pretty much finished my first working Symbian application, but in my hastened
For some weird reason, the codes below are first working, then website is redirecting
I'm working on my first object oriented bit of python and I have the
I'm working on a Java program that needs to send an image (preferably in
I'm back with another similar question. I am currently working on a Java program
I'm having two files that I've to invoke from a java program: a batch
I finished first year comp sci. And i want to spend some time working

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.