Can you redefine an object of a class?

-2

I have a Parent class that receives two mandatory parameters: the number of rows and columns. And I want to reuse an object and change the number of rows and columns, something like this:

for(i=1; i<=10; i++){
   Matriz M(i, i);
   //Hacer algo con la matriz
}

Is there any way I can do it? I've searched for it with pointers and using new and delete but I'm not clear on how to pass the mandatory arguments to each array.

    
asked by Reigal 29.09.2017 в 22:08
source

1 answer

0

If that matrix class is defined by you, you could have two methods of assigning properties to columns and rows:

public class Matriz{
  private int col;
  private int fil;

  public int col{
     set{col = value;}
  }

  public int fil{
     set{fil = value;}
  }
}

After that, you could reuse the same object, modifying the values of the properties:

Matriz M = new Matriz();
for(i=1; i<=10; i++){
   M.col = i;
   M.fil = i;
   //Hacer algo con la matriz
}
    
answered by 29.09.2017 / 22:40
source