167k views
2 votes
Consider the following constructor for an immutable matrix ADT:

public class SolnMatrix implements Matrix {
private final int [ ] [ ] data ;
public SolnMat r ix ( int [ ] [ ] matr ix ) {
data = matrix
}

// the usual operations follow . . .
Will this class behave as expected? Explain.

User Fxbois
by
3.7k points

1 Answer

5 votes

Answer:

No

Step-by-step explanation:

When a class is an immutable classes, if one wants to perform

deep copy, it must be performed in constructor.

But in the above program case, constructor does not perform deep copy.

Hence, this class constructor does not behave properly.

User Gavin Campbell
by
3.4k points