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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:24:36+00:00 2026-05-11T17:24:36+00:00

I’m currently trying to draw shapes with 2D Arrays. In my class there is

  • 0

I’m currently trying to draw shapes with 2D Arrays. In my class there is a global array defined with public char canvas[][];

Up until now, I have only declared arrays with char canvas[][] = new char[height][width];

If this Array has already been declared, and I’m not supposed to amend the code I’ve been given, how do I call an instance of that array so that I can use it?

thanks.

(edit)

class DrawingSystem {

    public char canvas[][];

       public static void makeNewCanvas(int tmpWidth, int tmpHeight) {

        canvas[][] = new char[tmpHeight][tmpWidth];

        for (int row=0; row<tmpHeight; row++) {
            for (int col=0; col<tmpWidth; col++) {
                canvas[row][col] = ' ';
            }
        }       
    }
  • 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-11T17:24:36+00:00Added an answer on May 11, 2026 at 5:24 pm

    You have an incompatibility between static methods and instance variables.

    Think about it this way: an instance variable is associated with a specific instance of a class; a static variable is associated with the class itself. You call static methods via the class:

    ClassI.callStaticMethod();
    

    Whereas you call an instance method via an instance of the class:

    public ClassI classObj = new ClassI();
    classObj.callInstanceMethod();
    

    In the code you posted, there’s an instance variable (“canvas”) being set in a static method (main is associated with the Class, not an instance).

    Therefore, you’ll need to create instance methods to modify/update your “canvas”, and create an instance of the class within the static function. This object (an “instance”) can be used to update the instance variable.

    Here’s an example:

    public class Foo {
        public char canvas[][];
    
        public static void main(String[] args) {
            Foo fooObj = new Foo(); //creates an instance of this class
            fooObj.createCanvas(2, 2);
            fooObj.modifyCanvas(0, 0, 'c');
        }
    
        public void createCanvas(int x, int y) {
            canvas = new char[x][y];
        }
        public void modifyCanvas(int x, int y, char c) {
            canvas[x][y] = c;
        }
    }
    

    This obviously isn’t a one-to-one correlation to your assignment, but I’m sure you’ll be able to adapt it to what you’re doing 🙂

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I know there's a lot of other questions out there that deal with this

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.