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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:51:06+00:00 2026-05-15T12:51:06+00:00

I need help with this piece of code. public class ParkingLot { static int

  • 0

I need help with this piece of code.

public class ParkingLot {

static int MAX = 5;
static Car[] Slot = new Car[MAX];

public static void main(String[] args) {


    Slot[0] = new Car("1234", "White");
    Slot[1] = new Car("5678", "Black");

}

public static void Allot() {
    for (int i = 0; i <= Slot.length; i++) {
        System.out.println(Slot.getNo);

    }
}

I am storing a Car Object in Slot. I wish to print/access the No and Colour of the car stored in slot. How do I go about doing that?

  • 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-15T12:51:06+00:00Added an answer on May 15, 2026 at 12:51 pm

    Well, if car has a public property, or a public getter method (this is preferable – getNumber() and getColour()), you can call them while iterating the array with the for-each loop:

    for (Car car : slot) {
        System.out.println(car.getColour());
    }
    

    Note that I’ve lowercased slot – variable names in Java should be lowercase. I’d also advise for naming the array with plural name – i.e. slots.

    Note also that the way of iteration provided by others is possible, but not recommended for the basic case of iterating the whole array. Effective Java (Bloch) recommends using the foreach loop whenever possible.

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

Sidebar

Related Questions

I need help with debugging this piece of code. I know the problem is
I am new to android and need help on this. I have two views
Sorry to bother again, but I really need help transforming this Python2 code into
I have this piece of code, and I need to target only the first
Iam a perl newbie and need help in understanding the below piece of code.
I need help with a piece of code I'm writing. I want to compute
I have been staring myself blind at this piece of javascript code, I need
I need help with the following piece of code, I would like to see
This is my piece of code and i need to get more than one
I really need help this time - Joomla 2.5 and latest K2. I'm using

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.