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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:04:35+00:00 2026-06-17T06:04:35+00:00

I have a class Floor which has a Stack of Blocks and I don’t

  • 0

I have a class Floor which has a Stack of Blocks and I don’t know how to initialize it. I had tried like this:

public class Floor {
    private Stack<Block> stack;
    private static int size;
    public void setStack(Stack<Block> stack) {
        this.stack = stack;
    }
    public void addBlock(Block b){
        stack.push(b);
    }
}

public class InputDevice {
    Block a0=new Block('I',false);
    Floor [] floor=new Floor[5];
    Stack<Block> stack=new Stack<Block>();
    floor[0].setStack(stack);
    floor[0].addBlock(a0);
}
  • 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-06-17T06:04:36+00:00Added an answer on June 17, 2026 at 6:04 am

    You’ve not initialized any of the Floor objects in the array yet. When you create an array of objects it’s like creating an egg carton. You can’t use any eggs until you put some in the carton first. You can’t use any objects in the array before you’ve initialized them, which is often done within a for loop. i.e.,

    Floor [] floor=new Floor[5];
    for (int i = 0; i < floor.length; i++) {
      floor[i] = new Floor();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a C# class like this: [XmlRoot(floors)] public class FloorCollection { [XmlElement(floor)]
Hi i have the following super class class Room: def __init__(self,building,floor,number): self.building=building self.floor=floor self.number=number
I have Class and Student objects. Both have collection of another as property. Which
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
We have class lua. In lua class there is a method registerFunc() which is
i have my auto-generated linq to sql classes, and i extend this class using
I have a bunch of div's like <div class=slides> <div id=box_bg> <div class=previous></div> <img
g++ (GCC) 4.6.0 I have the following class and I am trying to initialize
I have a CognitiveEntity class, defined this way: class CognitiveEntity : public Object {
I have the following script which works, but I don't think it's a nice

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.