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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:27:09+00:00 2026-05-17T19:27:09+00:00

I know what a static array is and how to use it in Java,

  • 0

I know what a static array is and how to use it in Java, but my Prof assigned us a program and for one of the many classes we had to create, he asked us to ‘use a static array’ in such a way that multiple objects will store their data there.

For instance, if the objects were car garages, then each garage instance would store in a 100×3 static array their data:

 1, honda, four-door
 3, toyota, two-door
 1, bicycle, -1
 1, ford, pickup
 2, ford, fiesta
 3, chevy, two-door
 3, bicycle, -1

The -1 indicates the end of each garage.

That’s a lousy example, but you get the idea.

So, I am thinking that what he wants is kind of like this:

In the demo class (which is the main), I will declare an instance of a class I made with the static array in it:

      PublicAccessArray p1 = new  PublicAccessArray();

Then that class starts off like:

      public class PublicAccessArray {

      public static int[][] accessArray;

      public static void PublicAccessArray()
      {
          accessArray = new int[100][3];
      ...

And then my class that will create the objects to use the static array will look like:

      public class ClassThatUsesTheStaticArray {
           public void ClassThatUsesTheStaticArray (PublicAccessArray array1)
           {...

So then back in the demo/main class I would instantiate those objects with:

      ClassThatUsesTheStaticArray  c1= new ClassThatUsesTheStaticArray (p1);

I think that’s what he means, and I know that the static array should look like the example I gave (though it uses numbers as data/elements).

I know he wants us to instantiate the ClassThatUsesTheStaticArray objects from the demo/main class and the only way I can see to do that would be to pass the p1 array to it.

Does what I am doing seem to be the right way? I often an easier time doing the actual coding than figure out what my Prof. is actually asking us to do so I was wondering if that sounds like a way to ‘use a static array’.

  • 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-17T19:27:09+00:00Added an answer on May 17, 2026 at 7:27 pm

    I do not think that you are on a right way.
    First you cannot store “honda” or “toyota” in int array. So you need String array. The first column looks like index, so you do not have to store it in your array at all.

    Second, the example is not OO enough. I’d suggest you the following.

    Create class Vehicle:

    public abstract class Vehicle {
        private String name;
        // getters, setters, constructor...
    }
    

    Then create classes Car and Bicycle that extend Vehicle. These classes can contain other data:

    public class Car extends Vehicle {
        public static enum Type {PICKUP, }; // add here other types
        private String model;
        private int doorsCount;
        private Type type;
    }
    

    Now create class Garage:

    public class Garage {
        private List<Vehicle> vehicles;
        // other fields and methods relevant for garage.
    }
    

    This is the time to create static array of garages:

    private static Garage[] garages = new Garage[100];
    

    You can populate it using static initializer (I assume here existence of convenient constructors I did not mention in my explanation):

    static {
        Vehicle honda = new Car("honda", 4);
        Vehicle toyota = new Car("toyota", 2);    
        Vehicle bicycle = new Bicycle("bicycle");    
        garaghes[0] = new Garage("First", new Vehicle[] {honda, toyota, bicycle});
    
        Vehicle fiesta = new Car("ford", "fiesta");
        Vehicle pickup = new Car("ford", Car.Type.PICKUP);
        garaghes[1] = new Garage("Second", new Vehicle[] {fiesta, pickup});
    }
    

    I believe your Prof will be satisfied. Good luck!

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

Sidebar

Related Questions

I'm trying to use double-checked locking to maintain an array of binomial coefficients, but
I use Type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) to retrieve an array of
I'm would like to know how could I inherent static field from Java class
I would like to know difference between static variables and global variables in terms
I know I can get the public static members of a class by doing
I would like to know what is the difference between initializing a static member
What tools are there available for static analysis against C# code? I know about
Know of an OCAML/CAML IDE? Especially one that runs on Linux?
I know this sounds like a broad question but I can narrow it down
I decided to implement a very simple program recursively, to see how well Java

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.