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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:43:41+00:00 2026-05-17T17:43:41+00:00

I created an Matrix object (like the math Matrix, a 4×4 block of numbers

  • 0

I created an Matrix object (like the math Matrix, a 4×4 block of numbers for instance) and it works fine, can set row,col,variable just fine, but, I cant have more than one of the same object, I have it creating an ArrayList of a dozen Matrix objects, each with the three variables, but when I call changeVar(Matrix x,int variable) and refresh the printout of the matrix, it changes all of the numbers to what i changed the variable to. So it looks like its just creating the same instance over and over, and if you change one, it changes them all, am i missing anything obvious?

public class Matrices {

    private static int row, col, value, newRow, newCol;

    public Matrices(int row, int col, int value) {
        this.value = value;
        this.row = row;
        this.col = col;
    }

    public static void setRow(int row) {
        Matrices.row = row;
    }

    public static void setValue(int value) {
        Matrices.value = value;
    }

    public static void setCol(int col) {
        Matrices.col = col;
    }

    public static int getCol(Matrices x) {
        return col;
    }

    public static int getRow(Matrices x) {
        return row;
    }

    public static int getValue(Matrices x) {
        return value;
    }

    public static Matrices changeValue(Matrices x, int value) {
        newRow = getRow(x);
        newCol = getCol(x);
        return new Matrices(newRow, newCol, value);
    }
}
  • 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-17T17:43:42+00:00Added an answer on May 17, 2026 at 5:43 pm

    You are using static members. Static members are shared across all instances.

    Don’t do that: remove the ‘static’ keyword.

    I am surprised there were no warnings on the this.x = x lines…

    Happy coding

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

Sidebar

Related Questions

I recently created a generic Matrix<T> class that acts as a wrapper around a
How to create the transformation matrix (4x4) that transforms a cylinder (of height 1
How can I create a const boost matrix? The following did not work: const
Using JavaScript, how do I create an HTML table that can "accept" numeric matrix
Created .NET WCF service, tested it - works. Generated schemas from Data and service
Probably about 20 chars' solution. I want colnames to matrix(...) -object or alternative way
How can I clear objects (and the memory they occupy) created via rpy? import
Does anyone know of a function that can create an lm object given a
I think it can be done by applying the transformation matrix of the scenegraph
Hi I have to create a matrix of object with certain dimension.is it possible.the

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.